lint: fix all golang lint after big merge (#1861)
This commit is contained in:
parent
7b94e6163f
commit
0f622f3829
@ -48,24 +48,11 @@ linters-settings:
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
- path: crypto/blake2b/
|
||||
- path: core/state/metrics.go
|
||||
linters:
|
||||
- deadcode
|
||||
- path: crypto/bn256/cloudflare
|
||||
- unused
|
||||
- path: core/txpool/legacypool/list.go
|
||||
linters:
|
||||
- deadcode
|
||||
- path: p2p/discv5/
|
||||
linters:
|
||||
- deadcode
|
||||
- path: core/vm/instructions_test.go
|
||||
linters:
|
||||
- goconst
|
||||
- path: cmd/faucet/
|
||||
linters:
|
||||
- deadcode
|
||||
- path: crypto/bn256/cloudflare/optate.go
|
||||
linters:
|
||||
- deadcode
|
||||
- staticcheck
|
||||
- path: internal/build/pgp.go
|
||||
text: 'SA1019: "golang.org/x/crypto/openpgp" is deprecated: this package is unmaintained except for security fixes.'
|
||||
|
@ -148,7 +148,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
website := new(bytes.Buffer)
|
||||
err := template.Must(template.New("").Parse(string(websiteTmpl))).Execute(website, map[string]interface{}{
|
||||
err := template.Must(template.New("").Parse(websiteTmpl)).Execute(website, map[string]interface{}{
|
||||
"Network": *netnameFlag,
|
||||
"Amounts": amounts,
|
||||
"Recaptcha": *captchaToken,
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -70,11 +69,7 @@ func TestOfflineBlockPrune(t *testing.T) {
|
||||
}
|
||||
|
||||
func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64) {
|
||||
datadir, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temporary datadir: %v", err)
|
||||
}
|
||||
os.RemoveAll(datadir)
|
||||
datadir := t.TempDir()
|
||||
|
||||
chaindbPath := filepath.Join(datadir, "chaindata")
|
||||
oldAncientPath := filepath.Join(chaindbPath, "ancient")
|
||||
@ -86,9 +81,6 @@ func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64
|
||||
|
||||
//Initialize a block pruner for pruning, only remain amountReserved blocks backward.
|
||||
testBlockPruner := pruner.NewBlockPruner(db, node, oldAncientPath, newAncientPath, amountReserved)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to make new blockpruner: %v", err)
|
||||
}
|
||||
if err := testBlockPruner.BlockPruneBackUp(chaindbPath, 512, utils.MakeDatabaseHandles(0), "", false, false); err != nil {
|
||||
t.Fatalf("Failed to back up block: %v", err)
|
||||
}
|
||||
|
@ -134,5 +134,4 @@ func main() {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ package ethash
|
||||
import (
|
||||
"time"
|
||||
|
||||
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
@ -125,7 +125,6 @@ func simulateValidatorOutOfService(totalValidators int, downValidators int) {
|
||||
}
|
||||
|
||||
func producerBlockDelay(candidates map[int]bool, height, numOfValidators int) (int, uint64) {
|
||||
|
||||
s := rand.NewSource(int64(height))
|
||||
r := rand.New(s)
|
||||
n := numOfValidators
|
||||
@ -220,7 +219,6 @@ func (b *MockBlock) GetJustifiedNumberAndHash() (uint64, common.Hash, error) {
|
||||
justifiedBlock = curBlock.parent
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return justifiedBlock.blockNumber, justifiedBlock.blockHash, nil
|
||||
|
@ -26,8 +26,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
@ -37,7 +35,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/ethdb/memorydb"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -45,40 +42,12 @@ var (
|
||||
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
contractCode, _ = hex.DecodeString("608060405260016000806101000a81548160ff02191690831515021790555034801561002a57600080fd5b506101688061003a6000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806389a2d8011461003b578063b0483f4814610059575b600080fd5b610043610075565b60405161005091906100f4565b60405180910390f35b610073600480360381019061006e91906100bc565b61008b565b005b60008060009054906101000a900460ff16905090565b806000806101000a81548160ff02191690831515021790555050565b6000813590506100b68161011b565b92915050565b6000602082840312156100ce57600080fd5b60006100dc848285016100a7565b91505092915050565b6100ee8161010f565b82525050565b600060208201905061010960008301846100e5565b92915050565b60008115159050919050565b6101248161010f565b811461012f57600080fd5b5056fea264697066735822122092f788b569bfc3786e90601b5dbec01cfc3d76094164fd66ca7d599c4239fc5164736f6c63430008000033")
|
||||
contractAddr = common.HexToAddress("0xe74a3c7427cda785e0000d42a705b1f3fd371e09")
|
||||
contractSlot = common.HexToHash("0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563")
|
||||
contractData1, _ = hex.DecodeString("b0483f480000000000000000000000000000000000000000000000000000000000000000")
|
||||
contractData2, _ = hex.DecodeString("b0483f480000000000000000000000000000000000000000000000000000000000000001")
|
||||
commonGas = 192138
|
||||
// testAddr is the Ethereum address of the tester account.
|
||||
testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
|
||||
|
||||
checkBlocks = map[int]checkBlockParam{
|
||||
12: {
|
||||
txs: []checkTransactionParam{
|
||||
{
|
||||
to: &contractAddr,
|
||||
slot: contractSlot,
|
||||
value: []byte{01},
|
||||
},
|
||||
}},
|
||||
|
||||
13: {
|
||||
txs: []checkTransactionParam{
|
||||
{
|
||||
to: &contractAddr,
|
||||
slot: contractSlot,
|
||||
value: []byte{},
|
||||
},
|
||||
}},
|
||||
14: {
|
||||
txs: []checkTransactionParam{
|
||||
{
|
||||
to: &contractAddr,
|
||||
slot: contractSlot,
|
||||
value: []byte{01},
|
||||
},
|
||||
}},
|
||||
}
|
||||
// testBlocks is the test parameters array for specific blocks.
|
||||
testBlocks = []testBlockParam{
|
||||
{
|
||||
@ -175,16 +144,6 @@ type testBlockParam struct {
|
||||
txs []testTransactionParam
|
||||
}
|
||||
|
||||
type checkTransactionParam struct {
|
||||
to *common.Address
|
||||
slot common.Hash
|
||||
value []byte
|
||||
}
|
||||
|
||||
type checkBlockParam struct {
|
||||
txs []checkTransactionParam
|
||||
}
|
||||
|
||||
// testBackend is a mock implementation of the live Ethereum message handler. Its
|
||||
// purpose is to allow testing the request/reply workflows and wire serialization
|
||||
// in the `eth` protocol without actually doing any data processing.
|
||||
@ -251,7 +210,6 @@ func newTestBackendWithGenerator(blocks int, lightProcess bool) *testBackend {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
bs, _ := GenerateChain(params.TestChainConfig, chain.Genesis(), ethash.NewFaker(), db, blocks, generator)
|
||||
if _, err := chain.InsertChain(bs); err != nil {
|
||||
@ -271,21 +229,6 @@ func (b *testBackend) close() {
|
||||
|
||||
func (b *testBackend) Chain() *BlockChain { return b.chain }
|
||||
|
||||
func rawDataToDiffLayer(data rlp.RawValue) (*types.DiffLayer, error) {
|
||||
var diff types.DiffLayer
|
||||
hasher := sha3.NewLegacyKeccak256()
|
||||
err := rlp.DecodeBytes(data, &diff)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hasher.Write(data)
|
||||
var diffHash common.Hash
|
||||
hasher.Sum(diffHash[:0])
|
||||
diff.DiffHash.Store(diffHash)
|
||||
hasher.Reset()
|
||||
return &diff, nil
|
||||
}
|
||||
|
||||
func TestFreezeDiffLayer(t *testing.T) {
|
||||
blockNum := 1024
|
||||
fullBackend := newTestBackend(blockNum, true)
|
||||
@ -366,7 +309,6 @@ func newTwoForkedBlockchains(len1, len2 int) (chain1 *BlockChain, chain2 *BlockC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
bs1, _ := GenerateChain(params.TestChainConfig, chain1.Genesis(), ethash.NewFaker(), db1, len1, generator1)
|
||||
if _, err := chain1.InsertChain(bs1); err != nil {
|
||||
|
@ -129,6 +129,8 @@ func (it *insertIterator) next() (*types.Block, error) {
|
||||
//
|
||||
// Both header and body validation errors (nil too) is cached into the iterator
|
||||
// to avoid duplicating work on the following next() call.
|
||||
//
|
||||
// nolint:unused
|
||||
func (it *insertIterator) peek() (*types.Block, error) {
|
||||
// If we reached the end of the chain, abort
|
||||
if it.index+1 >= len(it.chain) {
|
||||
|
@ -339,8 +339,8 @@ func testInsertAfterMerge(t *testing.T, blockchain *BlockChain, i, n int, full b
|
||||
// with various length chains.
|
||||
func TestExtendCanonicalHeaders(t *testing.T) {
|
||||
testExtendCanonical(t, false, false)
|
||||
|
||||
}
|
||||
|
||||
func TestExtendCanonicalBlocks(t *testing.T) {
|
||||
testExtendCanonical(t, true, false)
|
||||
testExtendCanonical(t, true, true)
|
||||
@ -452,7 +452,6 @@ func TestLongerForkHeaders(t *testing.T) {
|
||||
func TestLongerForkBlocks(t *testing.T) {
|
||||
testLongerFork(t, true, false)
|
||||
testLongerFork(t, true, true)
|
||||
|
||||
}
|
||||
|
||||
func testLongerFork(t *testing.T, full, pipeline bool) {
|
||||
|
@ -98,7 +98,6 @@ func NewID(config *params.ChainConfig, genesis common.Hash, head, time uint64) I
|
||||
return ID{Hash: checksumToBytes(hash), Next: 0}
|
||||
}
|
||||
|
||||
|
||||
// NewIDWithChain calculates the Ethereum fork ID from an existing chain instance.
|
||||
func NewIDWithChain(chain Blockchain) ID {
|
||||
head := chain.CurrentHeader()
|
||||
|
@ -159,7 +159,7 @@ func NewFreezer(datadir string, namespace string, readonly bool, offset uint64,
|
||||
// Create the write batch.
|
||||
freezer.writeBatch = newFreezerBatch(freezer)
|
||||
|
||||
log.Info("Opened ancient database", "database", datadir, "readonly", readonly, "frozen", freezer.frozen)
|
||||
log.Info("Opened ancient database", "database", datadir, "readonly", readonly, "frozen", freezer.frozen.Load())
|
||||
return freezer, nil
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ func TestFreezerReadonlyValidate(t *testing.T) {
|
||||
|
||||
// Re-openening as readonly should fail when validating
|
||||
// table lengths.
|
||||
f, err = NewFreezer(dir, "", true, 0, 2049, tables)
|
||||
_, err = NewFreezer(dir, "", true, 0, 2049, tables)
|
||||
if err == nil {
|
||||
t.Fatal("readonly freezer should fail with differing table lengths")
|
||||
}
|
||||
|
@ -40,9 +40,6 @@ var (
|
||||
// headFastBlockKey tracks the latest known incomplete block's hash during fast sync.
|
||||
headFastBlockKey = []byte("LastFast")
|
||||
|
||||
// headFinalizedBlockKey tracks the latest known finalized block hash.
|
||||
headFinalizedBlockKey = []byte("LastFinalized")
|
||||
|
||||
// persistentStateIDKey tracks the id of latest stored state(for path-based only).
|
||||
persistentStateIDKey = []byte("LastStateID")
|
||||
|
||||
@ -70,9 +67,6 @@ var (
|
||||
// snapshotSyncStatusKey tracks the snapshot sync status across restarts.
|
||||
snapshotSyncStatusKey = []byte("SnapshotSyncStatus")
|
||||
|
||||
// skeletonSyncStatusKey tracks the skeleton sync status across restarts.
|
||||
skeletonSyncStatusKey = []byte("SkeletonSyncStatus")
|
||||
|
||||
// trieJournalKey tracks the in-memory trie node layers across restarts.
|
||||
trieJournalKey = []byte("TrieJournal")
|
||||
|
||||
|
@ -450,7 +450,6 @@ func (p *BlockPruner) backUpOldDb(name string, cache, handles int, namespace str
|
||||
|
||||
// Backup the ancient data for the old ancient db, i.e. the most recent 128 blocks in ancient db.
|
||||
func (p *BlockPruner) BlockPruneBackUp(name string, cache, handles int, namespace string, readonly, interrupt bool) error {
|
||||
|
||||
start := time.Now()
|
||||
|
||||
if err := p.backUpOldDb(name, cache, handles, namespace, readonly, interrupt); err != nil {
|
||||
|
@ -192,7 +192,6 @@ func (p *triePrefetcher) mainLoop() {
|
||||
}
|
||||
fetcher.lock.Unlock()
|
||||
p.storageWasteMeter.Mark(int64(len(fetcher.seen)))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +138,6 @@ func (p *statePrefetcher) PrefetchMining(txs TransactionsByPriceAndNonce, header
|
||||
return
|
||||
default:
|
||||
if count++; count%checkInterval == 0 {
|
||||
|
||||
txset.Forward(*txCurr)
|
||||
}
|
||||
tx := txset.PeekWithUnwrap()
|
||||
|
@ -60,7 +60,6 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
// For contract upgrades, the following information is from `bsc-genesis-contract`, to be specifically,
|
||||
// 1) `CommitUrl` is the specific git commit, based on which the byte code is compiled from;
|
||||
// 2) `Code` is the byte code of the contract, which is generated by compiling `bsc-genesis-contract`.
|
||||
|
@ -415,7 +415,7 @@ func (pool *LegacyPool) loop() {
|
||||
}()
|
||||
pool.mu.RUnlock()
|
||||
if len(reannoTxs) > 0 {
|
||||
pool.reannoTxFeed.Send(core.ReannoTxsEvent{reannoTxs})
|
||||
pool.reannoTxFeed.Send(core.ReannoTxsEvent{Txs: reannoTxs})
|
||||
}
|
||||
|
||||
// Handle local transaction journal rotation
|
||||
@ -427,7 +427,6 @@ func (pool *LegacyPool) loop() {
|
||||
}
|
||||
pool.mu.Unlock()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ type ConsensusState struct {
|
||||
// | chainID | height | appHash | curValidatorSetHash | [{validator pubkey, voting power}] |
|
||||
// | 32 bytes | 8 bytes | 32 bytes | 32 bytes | [{32 bytes, 8 bytes}] |
|
||||
func DecodeConsensusState(input []byte) (ConsensusState, error) {
|
||||
|
||||
minimumLength := chainIDLength + heightLength + appHashLength + validatorSetHashLength
|
||||
singleValidatorBytesLength := validatorPubkeyLength + validatorVotingPowerLength
|
||||
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -415,7 +414,7 @@ func setUpKeyManager(t *testing.T) (string, string) {
|
||||
if err := os.MkdirAll(filepath.Dir(walletPasswordDir), 0700); err != nil {
|
||||
t.Fatalf("failed to create walletPassword dir: %v", err)
|
||||
}
|
||||
if err := ioutil.WriteFile(walletPasswordDir, []byte(password), 0600); err != nil {
|
||||
if err := os.WriteFile(walletPasswordDir, []byte(password), 0600); err != nil {
|
||||
t.Fatalf("failed to write wallet password dir: %v", err)
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package vote
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -41,7 +41,7 @@ func NewVoteSigner(blsPasswordPath, blsWalletPath string) (*VoteSigner, error) {
|
||||
return nil, fmt.Errorf("BLS wallet did not exists")
|
||||
}
|
||||
|
||||
walletPassword, err := ioutil.ReadFile(blsPasswordPath)
|
||||
walletPassword, err := os.ReadFile(blsPasswordPath)
|
||||
if err != nil {
|
||||
log.Error("Read BLS wallet password", "err", err)
|
||||
return nil, err
|
||||
|
@ -199,9 +199,8 @@ func miller(q *twistPoint, p *curvePoint) *gfP12 {
|
||||
r = newR
|
||||
|
||||
r2.Square(&minusQ2.y)
|
||||
a, b, c, newR = lineFunctionAdd(r, minusQ2, bAffine, r2)
|
||||
a, b, c, _ = lineFunctionAdd(r, minusQ2, bAffine, r2)
|
||||
mulLine(ret, a, b, c)
|
||||
r = newR
|
||||
|
||||
return ret
|
||||
}
|
||||
|
@ -1,143 +0,0 @@
|
||||
// Copyright 2021 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Package catalyst implements the temporary eth1/eth2 RPC integration.
|
||||
package catalyst
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/eth"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
// Register adds the engine API to the full node.
|
||||
func Register(stack *node.Node, backend *eth.Ethereum) error {
|
||||
log.Warn("Engine API enabled", "protocol", "eth")
|
||||
stack.RegisterAPIs([]rpc.API{
|
||||
{
|
||||
Namespace: "engine",
|
||||
Service: NewConsensusAPI(backend),
|
||||
Authenticated: true,
|
||||
},
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
// invalidBlockHitEviction is the number of times an invalid block can be
|
||||
// referenced in forkchoice update or new payload before it is attempted
|
||||
// to be reprocessed again.
|
||||
invalidBlockHitEviction = 128
|
||||
|
||||
// invalidTipsetsCap is the max number of recent block hashes tracked that
|
||||
// have lead to some bad ancestor block. It's just an OOM protection.
|
||||
invalidTipsetsCap = 512
|
||||
|
||||
// beaconUpdateStartupTimeout is the time to wait for a beacon client to get
|
||||
// attached before starting to issue warnings.
|
||||
beaconUpdateStartupTimeout = 30 * time.Second
|
||||
|
||||
// beaconUpdateConsensusTimeout is the max time allowed for a beacon client
|
||||
// to send a consensus update before it's considered offline and the user is
|
||||
// warned.
|
||||
beaconUpdateConsensusTimeout = 2 * time.Minute
|
||||
|
||||
// beaconUpdateWarnFrequency is the frequency at which to warn the user that
|
||||
// the beacon client is offline.
|
||||
beaconUpdateWarnFrequency = 5 * time.Minute
|
||||
)
|
||||
|
||||
// All methods provided over the engine endpoint.
|
||||
var caps = []string{
|
||||
"engine_forkchoiceUpdatedV1",
|
||||
"engine_forkchoiceUpdatedV2",
|
||||
"engine_exchangeTransitionConfigurationV1",
|
||||
"engine_getPayloadV1",
|
||||
"engine_getPayloadV2",
|
||||
"engine_getPayloadV3",
|
||||
"engine_newPayloadV1",
|
||||
"engine_newPayloadV2",
|
||||
"engine_newPayloadV3",
|
||||
"engine_getPayloadBodiesByHashV1",
|
||||
"engine_getPayloadBodiesByRangeV1",
|
||||
}
|
||||
|
||||
type ConsensusAPI struct {
|
||||
eth *eth.Ethereum
|
||||
|
||||
remoteBlocks *headerQueue // Cache of remote payloads received
|
||||
localBlocks *payloadQueue // Cache of local payloads generated
|
||||
|
||||
// The forkchoice update and new payload method require us to return the
|
||||
// latest valid hash in an invalid chain. To support that return, we need
|
||||
// to track historical bad blocks as well as bad tipsets in case a chain
|
||||
// is constantly built on it.
|
||||
//
|
||||
// There are a few important caveats in this mechanism:
|
||||
// - The bad block tracking is ephemeral, in-memory only. We must never
|
||||
// persist any bad block information to disk as a bug in Geth could end
|
||||
// up blocking a valid chain, even if a later Geth update would accept
|
||||
// it.
|
||||
// - Bad blocks will get forgotten after a certain threshold of import
|
||||
// attempts and will be retried. The rationale is that if the network
|
||||
// really-really-really tries to feed us a block, we should give it a
|
||||
// new chance, perhaps us being racey instead of the block being legit
|
||||
// bad (this happened in Geth at a point with import vs. pending race).
|
||||
// - Tracking all the blocks built on top of the bad one could be a bit
|
||||
// problematic, so we will only track the head chain segment of a bad
|
||||
// chain to allow discarding progressing bad chains and side chains,
|
||||
// without tracking too much bad data.
|
||||
invalidBlocksHits map[common.Hash]int // Ephemeral cache to track invalid blocks and their hit count
|
||||
invalidTipsets map[common.Hash]*types.Header // Ephemeral cache to track invalid tipsets and their bad ancestor
|
||||
invalidLock sync.Mutex // Protects the invalid maps from concurrent access
|
||||
|
||||
// Geth can appear to be stuck or do strange things if the beacon client is
|
||||
// offline or is sending us strange data. Stash some update stats away so
|
||||
// that we can warn the user and not have them open issues on our tracker.
|
||||
lastTransitionUpdate time.Time
|
||||
lastTransitionLock sync.Mutex
|
||||
lastForkchoiceUpdate time.Time
|
||||
lastForkchoiceLock sync.Mutex
|
||||
lastNewPayloadUpdate time.Time
|
||||
lastNewPayloadLock sync.Mutex
|
||||
|
||||
forkchoiceLock sync.Mutex // Lock for the forkChoiceUpdated method
|
||||
newPayloadLock sync.Mutex // Lock for the NewPayload method
|
||||
}
|
||||
|
||||
// NewConsensusAPI creates a new consensus api for the given backend.
|
||||
// The underlying blockchain needs to have a valid terminal total difficulty set.
|
||||
func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI {
|
||||
if eth.BlockChain().Config().TerminalTotalDifficulty == nil {
|
||||
log.Warn("Engine API started but chain not configured for merge yet")
|
||||
}
|
||||
api := &ConsensusAPI{
|
||||
eth: eth,
|
||||
remoteBlocks: newHeaderQueue(),
|
||||
localBlocks: newPayloadQueue(),
|
||||
invalidBlocksHits: make(map[common.Hash]int),
|
||||
invalidTipsets: make(map[common.Hash]*types.Header),
|
||||
}
|
||||
// eth.Downloader().SetBadBlockCallback(api.setInvalidAncestor)
|
||||
|
||||
return api
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
// Copyright 2022 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package catalyst
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/ethereum/go-ethereum/beacon/engine"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/miner"
|
||||
)
|
||||
|
||||
// maxTrackedPayloads is the maximum number of prepared payloads the execution
|
||||
// engine tracks before evicting old ones. Ideally we should only ever track the
|
||||
// latest one; but have a slight wiggle room for non-ideal conditions.
|
||||
const maxTrackedPayloads = 10
|
||||
|
||||
// maxTrackedHeaders is the maximum number of executed payloads the execution
|
||||
// engine tracks before evicting old ones. These are tracked outside the chain
|
||||
// during initial sync to allow ForkchoiceUpdate to reference past blocks via
|
||||
// hashes only. For the sync target it would be enough to track only the latest
|
||||
// header, but snap sync also needs the latest finalized height for the ancient
|
||||
// limit.
|
||||
const maxTrackedHeaders = 96
|
||||
|
||||
// payloadQueueItem represents an id->payload tuple to store until it's retrieved
|
||||
// or evicted.
|
||||
type payloadQueueItem struct {
|
||||
id engine.PayloadID
|
||||
payload *miner.Payload
|
||||
}
|
||||
|
||||
// payloadQueue tracks the latest handful of constructed payloads to be retrieved
|
||||
// by the beacon chain if block production is requested.
|
||||
type payloadQueue struct {
|
||||
payloads []*payloadQueueItem
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// newPayloadQueue creates a pre-initialized queue with a fixed number of slots
|
||||
// all containing empty items.
|
||||
func newPayloadQueue() *payloadQueue {
|
||||
return &payloadQueue{
|
||||
payloads: make([]*payloadQueueItem, maxTrackedPayloads),
|
||||
}
|
||||
}
|
||||
|
||||
// put inserts a new payload into the queue at the given id.
|
||||
func (q *payloadQueue) put(id engine.PayloadID, payload *miner.Payload) {
|
||||
q.lock.Lock()
|
||||
defer q.lock.Unlock()
|
||||
|
||||
copy(q.payloads[1:], q.payloads)
|
||||
q.payloads[0] = &payloadQueueItem{
|
||||
id: id,
|
||||
payload: payload,
|
||||
}
|
||||
}
|
||||
|
||||
// get retrieves a previously stored payload item or nil if it does not exist.
|
||||
func (q *payloadQueue) get(id engine.PayloadID, full bool) *engine.ExecutionPayloadEnvelope {
|
||||
q.lock.RLock()
|
||||
defer q.lock.RUnlock()
|
||||
|
||||
for _, item := range q.payloads {
|
||||
if item == nil {
|
||||
return nil // no more items
|
||||
}
|
||||
if item.id == id {
|
||||
if !full {
|
||||
return item.payload.Resolve()
|
||||
}
|
||||
return item.payload.ResolveFull()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// has checks if a particular payload is already tracked.
|
||||
func (q *payloadQueue) has(id engine.PayloadID) bool {
|
||||
q.lock.RLock()
|
||||
defer q.lock.RUnlock()
|
||||
|
||||
for _, item := range q.payloads {
|
||||
if item == nil {
|
||||
return false
|
||||
}
|
||||
if item.id == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// headerQueueItem represents an hash->header tuple to store until it's retrieved
|
||||
// or evicted.
|
||||
type headerQueueItem struct {
|
||||
hash common.Hash
|
||||
header *types.Header
|
||||
}
|
||||
|
||||
// headerQueue tracks the latest handful of constructed headers to be retrieved
|
||||
// by the beacon chain if block production is requested.
|
||||
type headerQueue struct {
|
||||
headers []*headerQueueItem
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// newHeaderQueue creates a pre-initialized queue with a fixed number of slots
|
||||
// all containing empty items.
|
||||
func newHeaderQueue() *headerQueue {
|
||||
return &headerQueue{
|
||||
headers: make([]*headerQueueItem, maxTrackedHeaders),
|
||||
}
|
||||
}
|
||||
|
||||
// put inserts a new header into the queue at the given hash.
|
||||
func (q *headerQueue) put(hash common.Hash, data *types.Header) {
|
||||
q.lock.Lock()
|
||||
defer q.lock.Unlock()
|
||||
|
||||
copy(q.headers[1:], q.headers)
|
||||
q.headers[0] = &headerQueueItem{
|
||||
hash: hash,
|
||||
header: data,
|
||||
}
|
||||
}
|
||||
|
||||
// get retrieves a previously stored header item or nil if it does not exist.
|
||||
func (q *headerQueue) get(hash common.Hash) *types.Header {
|
||||
q.lock.RLock()
|
||||
defer q.lock.RUnlock()
|
||||
|
||||
for _, item := range q.headers {
|
||||
if item == nil {
|
||||
return nil // no more items
|
||||
}
|
||||
if item.hash == hash {
|
||||
return item.header
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -47,9 +47,6 @@ var (
|
||||
MaxReceiptFetch = 256 // Amount of transaction receipts to allow fetching per request
|
||||
MaxStateFetch = 384 // Amount of node state values to allow fetching per request
|
||||
|
||||
diffFetchTick = 10 * time.Millisecond
|
||||
diffFetchLimit = 5
|
||||
|
||||
maxQueuedHeaders = 32 * 1024 // [eth/62] Maximum number of headers to queue for import (DOS protection)
|
||||
maxHeadersProcess = 2048 // Number of header download results to import at once into the chain
|
||||
maxResultsProcess = 2048 // Number of content download results to import at once into the chain
|
||||
@ -89,10 +86,6 @@ var (
|
||||
// peerDropFn is a callback type for dropping a peer detected as malicious.
|
||||
type peerDropFn func(id string)
|
||||
|
||||
// badBlockFn is a callback for the async beacon sync to notify the caller that
|
||||
// the origin header requested to sync to, produced a chain with a bad block.
|
||||
type badBlockFn func(invalid *types.Header, origin *types.Header)
|
||||
|
||||
// headerTask is a set of downloaded headers to queue along with their precomputed
|
||||
// hashes to avoid constant rehashing.
|
||||
type headerTask struct {
|
||||
@ -120,7 +113,6 @@ type Downloader struct {
|
||||
|
||||
// Callbacks
|
||||
dropPeer peerDropFn // Drops a peer for misbehaving
|
||||
badBlock badBlockFn // Reports a block as rejected by the chain
|
||||
|
||||
// Status
|
||||
synchroniseMock func(id string, hash common.Hash) error // Replacement for synchronise during testing
|
||||
@ -783,6 +775,7 @@ func (d *Downloader) findAncestor(p *peerConnection, localHeight uint64, remoteH
|
||||
remoteHeight = remoteHeader.Number.Uint64()
|
||||
)
|
||||
mode := d.getMode()
|
||||
/*
|
||||
switch mode {
|
||||
case FullSync:
|
||||
localHeight = d.blockchain.CurrentBlock().Number.Uint64()
|
||||
@ -791,6 +784,7 @@ func (d *Downloader) findAncestor(p *peerConnection, localHeight uint64, remoteH
|
||||
default:
|
||||
localHeight = d.lightchain.CurrentHeader().Number.Uint64()
|
||||
}
|
||||
*/
|
||||
p.log.Debug("Looking for common ancestor", "local", localHeight, "remote", remoteHeight)
|
||||
|
||||
// Recap floor value for binary search
|
||||
@ -1689,28 +1683,6 @@ func (d *Downloader) DeliverSnapPacket(peer *snap.Peer, packet snap.Packet) erro
|
||||
}
|
||||
}
|
||||
|
||||
// readHeaderRange returns a list of headers, using the given last header as the base,
|
||||
// and going backwards towards genesis. This method assumes that the caller already has
|
||||
// placed a reasonable cap on count.
|
||||
func (d *Downloader) readHeaderRange(last *types.Header, count int) []*types.Header {
|
||||
var (
|
||||
current = last
|
||||
headers []*types.Header
|
||||
)
|
||||
for {
|
||||
parent := d.lightchain.GetHeaderByHash(current.ParentHash)
|
||||
if parent == nil {
|
||||
break // The chain is not continuous, or the chain is exhausted
|
||||
}
|
||||
headers = append(headers, parent)
|
||||
if len(headers) >= count {
|
||||
break
|
||||
}
|
||||
current = parent
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
// reportSnapSyncProgress calculates various status reports and provides it to the user.
|
||||
func (d *Downloader) reportSnapSyncProgress(force bool) {
|
||||
// Initialize the sync start time if it's the first time we're reporting
|
||||
|
@ -390,7 +390,6 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
|
||||
}
|
||||
|
||||
gopool.Submit(func() {
|
||||
|
||||
for {
|
||||
select {
|
||||
case logs := <-matchedLogs:
|
||||
|
@ -197,7 +197,6 @@ type subscription struct {
|
||||
logs chan []*types.Log
|
||||
txs chan []*types.Transaction
|
||||
headers chan *types.Header
|
||||
finalizedHeaders chan *types.Header
|
||||
votes chan *types.VoteEnvelope
|
||||
installed chan struct{} // closed when the filter is installed
|
||||
err chan error // closed when the filter is uninstalled
|
||||
|
@ -43,7 +43,6 @@ import (
|
||||
)
|
||||
|
||||
type testBackend struct {
|
||||
mux *event.TypeMux
|
||||
db ethdb.Database
|
||||
sections uint64
|
||||
txFeed event.Feed
|
||||
|
@ -161,7 +161,6 @@ func testSendVotes(t *testing.T, protocol uint) {
|
||||
t.Errorf("missing vote: %x", vote.Hash())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRecvVotes67(t *testing.T) { testRecvVotes(t, eth.ETH67) }
|
||||
|
@ -865,5 +865,4 @@ func TestOptionMaxPeersPerIP(t *testing.T) {
|
||||
tryFunc(tryNum, "[2001:db8::11]:", "[2001:db8::22]:", true, doneCh5)
|
||||
}
|
||||
close(doneCh5)
|
||||
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/eth/protocols/bsc"
|
||||
"github.com/ethereum/go-ethereum/eth/protocols/trust"
|
||||
|
||||
@ -38,9 +36,6 @@ type ethPeer struct {
|
||||
snapExt *snapPeer // Satellite `snap` connection
|
||||
trustExt *trustPeer
|
||||
bscExt *bscPeer // Satellite `bsc` connection
|
||||
|
||||
syncDrop *time.Timer // Connection dropper if `eth` sync progress isn't validated in time
|
||||
snapWait chan struct{} // Notification channel for snap connections
|
||||
}
|
||||
|
||||
// info gathers and returns some `eth` protocol metadata known about a peer.
|
||||
|
@ -176,7 +176,7 @@ func (eth *Ethereum) StateAtBlock(ctx context.Context, block *types.Block, reexe
|
||||
return nil, nil, fmt.Errorf("stateAtBlock commit failed, number %d root %v: %w",
|
||||
current.NumberU64(), current.Root().Hex(), err)
|
||||
}
|
||||
statedb, err = state.New(root, database, nil)
|
||||
statedb, err = state.New(root, database, nil) // nolint:staticcheck
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("state reset after block %d failed: %v", current.NumberU64(), err)
|
||||
}
|
||||
|
@ -1489,6 +1489,33 @@ func (s *BlockChainAPI) replay(ctx context.Context, block *types.Block, accounts
|
||||
return result, statedb, nil
|
||||
}
|
||||
|
||||
// GetDiffAccountsWithScope returns detailed changes of some interested accounts in a specific block number.
|
||||
func (s *BlockChainAPI) GetDiffAccountsWithScope(ctx context.Context, blockNr rpc.BlockNumber, accounts []common.Address) (*types.DiffAccountsInBlock, error) {
|
||||
if s.b.Chain() == nil {
|
||||
return nil, fmt.Errorf("blockchain not support get diff accounts")
|
||||
}
|
||||
|
||||
block, err := s.b.BlockByNumber(ctx, blockNr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("block not found for block number (%d): %v", blockNr, err)
|
||||
}
|
||||
|
||||
needReplay, err := s.needToReplay(ctx, block, accounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !needReplay {
|
||||
return &types.DiffAccountsInBlock{
|
||||
Number: uint64(blockNr),
|
||||
BlockHash: block.Hash(),
|
||||
Transactions: make([]types.DiffAccountsInTx, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
result, _, err := s.replay(ctx, block, accounts)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *BlockChainAPI) GetVerifyResult(ctx context.Context, blockNr rpc.BlockNumber, blockHash common.Hash, diffHash common.Hash) *core.VerifyResult {
|
||||
return s.b.Chain().GetVerifyResult(uint64(blockNr), blockHash, diffHash)
|
||||
}
|
||||
|
@ -370,6 +370,7 @@ func newTestBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i i
|
||||
return backend
|
||||
}
|
||||
|
||||
// nolint:unused
|
||||
func (b *testBackend) setPendingBlock(block *types.Block) {
|
||||
b.pending = block
|
||||
}
|
||||
|
@ -846,7 +846,6 @@ type generateParams struct {
|
||||
coinbase common.Address // The fee recipient address for including transaction
|
||||
random common.Hash // The randomness generated by beacon chain, empty before the merge
|
||||
withdrawals types.Withdrawals // List of withdrawals to include in block.
|
||||
noExtra bool // Flag whether the extra field assignment is allowed
|
||||
prevWork *environment
|
||||
noTxs bool // Flag whether an empty block without any transaction is expected
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func NewSecure(stateRoot common.Hash, owner common.Hash, root common.Hash, db *D
|
||||
type StateTrie struct {
|
||||
trie Trie
|
||||
preimages *preimageStore
|
||||
hashKeyBuf [common.HashLength]byte
|
||||
hashKeyBuf [common.HashLength]byte //nolint:unused
|
||||
secKeyCache map[string][]byte
|
||||
secKeyCacheOwner *StateTrie // Pointer to self, replace the key cache on mismatch
|
||||
}
|
||||
@ -280,6 +280,8 @@ func (t *StateTrie) MustNodeIterator(start []byte) NodeIterator {
|
||||
// hashKey returns the hash of key as an ephemeral buffer.
|
||||
// The caller must not hold onto the return value because it will become
|
||||
// invalid on the next call to hashKey or secKey.
|
||||
//
|
||||
// no use hashKeyBuf for thread safe.
|
||||
func (t *StateTrie) hashKey(key []byte) []byte {
|
||||
hash := make([]byte, common.HashLength)
|
||||
h := newHasher(false)
|
||||
|
Loading…
Reference in New Issue
Block a user