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:
|
issues:
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
- path: crypto/blake2b/
|
- path: core/state/metrics.go
|
||||||
linters:
|
linters:
|
||||||
- deadcode
|
- unused
|
||||||
- path: crypto/bn256/cloudflare
|
- path: core/txpool/legacypool/list.go
|
||||||
linters:
|
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
|
- staticcheck
|
||||||
- path: internal/build/pgp.go
|
- path: internal/build/pgp.go
|
||||||
text: 'SA1019: "golang.org/x/crypto/openpgp" is deprecated: this package is unmaintained except for security fixes.'
|
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)
|
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,
|
"Network": *netnameFlag,
|
||||||
"Amounts": amounts,
|
"Amounts": amounts,
|
||||||
"Recaptcha": *captchaToken,
|
"Recaptcha": *captchaToken,
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -70,11 +69,7 @@ func TestOfflineBlockPrune(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64) {
|
func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64) {
|
||||||
datadir, err := ioutil.TempDir("", "")
|
datadir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to create temporary datadir: %v", err)
|
|
||||||
}
|
|
||||||
os.RemoveAll(datadir)
|
|
||||||
|
|
||||||
chaindbPath := filepath.Join(datadir, "chaindata")
|
chaindbPath := filepath.Join(datadir, "chaindata")
|
||||||
oldAncientPath := filepath.Join(chaindbPath, "ancient")
|
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.
|
//Initialize a block pruner for pruning, only remain amountReserved blocks backward.
|
||||||
testBlockPruner := pruner.NewBlockPruner(db, node, oldAncientPath, newAncientPath, amountReserved)
|
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 {
|
if err := testBlockPruner.BlockPruneBackUp(chaindbPath, 512, utils.MakeDatabaseHandles(0), "", false, false); err != nil {
|
||||||
t.Fatalf("Failed to back up block: %v", err)
|
t.Fatalf("Failed to back up block: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -134,5 +134,4 @@ func main() {
|
|||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ package ethash
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"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) {
|
func producerBlockDelay(candidates map[int]bool, height, numOfValidators int) (int, uint64) {
|
||||||
|
|
||||||
s := rand.NewSource(int64(height))
|
s := rand.NewSource(int64(height))
|
||||||
r := rand.New(s)
|
r := rand.New(s)
|
||||||
n := numOfValidators
|
n := numOfValidators
|
||||||
@ -220,7 +219,6 @@ func (b *MockBlock) GetJustifiedNumberAndHash() (uint64, common.Hash, error) {
|
|||||||
justifiedBlock = curBlock.parent
|
justifiedBlock = curBlock.parent
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return justifiedBlock.blockNumber, justifiedBlock.blockHash, nil
|
return justifiedBlock.blockNumber, justifiedBlock.blockHash, nil
|
||||||
|
@ -26,8 +26,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/sha3"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
@ -37,7 +35,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethdb/memorydb"
|
"github.com/ethereum/go-ethereum/ethdb/memorydb"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -45,40 +42,12 @@ var (
|
|||||||
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
contractCode, _ = hex.DecodeString("608060405260016000806101000a81548160ff02191690831515021790555034801561002a57600080fd5b506101688061003a6000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806389a2d8011461003b578063b0483f4814610059575b600080fd5b610043610075565b60405161005091906100f4565b60405180910390f35b610073600480360381019061006e91906100bc565b61008b565b005b60008060009054906101000a900460ff16905090565b806000806101000a81548160ff02191690831515021790555050565b6000813590506100b68161011b565b92915050565b6000602082840312156100ce57600080fd5b60006100dc848285016100a7565b91505092915050565b6100ee8161010f565b82525050565b600060208201905061010960008301846100e5565b92915050565b60008115159050919050565b6101248161010f565b811461012f57600080fd5b5056fea264697066735822122092f788b569bfc3786e90601b5dbec01cfc3d76094164fd66ca7d599c4239fc5164736f6c63430008000033")
|
contractCode, _ = hex.DecodeString("608060405260016000806101000a81548160ff02191690831515021790555034801561002a57600080fd5b506101688061003a6000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806389a2d8011461003b578063b0483f4814610059575b600080fd5b610043610075565b60405161005091906100f4565b60405180910390f35b610073600480360381019061006e91906100bc565b61008b565b005b60008060009054906101000a900460ff16905090565b806000806101000a81548160ff02191690831515021790555050565b6000813590506100b68161011b565b92915050565b6000602082840312156100ce57600080fd5b60006100dc848285016100a7565b91505092915050565b6100ee8161010f565b82525050565b600060208201905061010960008301846100e5565b92915050565b60008115159050919050565b6101248161010f565b811461012f57600080fd5b5056fea264697066735822122092f788b569bfc3786e90601b5dbec01cfc3d76094164fd66ca7d599c4239fc5164736f6c63430008000033")
|
||||||
contractAddr = common.HexToAddress("0xe74a3c7427cda785e0000d42a705b1f3fd371e09")
|
contractAddr = common.HexToAddress("0xe74a3c7427cda785e0000d42a705b1f3fd371e09")
|
||||||
contractSlot = common.HexToHash("0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563")
|
|
||||||
contractData1, _ = hex.DecodeString("b0483f480000000000000000000000000000000000000000000000000000000000000000")
|
contractData1, _ = hex.DecodeString("b0483f480000000000000000000000000000000000000000000000000000000000000000")
|
||||||
contractData2, _ = hex.DecodeString("b0483f480000000000000000000000000000000000000000000000000000000000000001")
|
contractData2, _ = hex.DecodeString("b0483f480000000000000000000000000000000000000000000000000000000000000001")
|
||||||
commonGas = 192138
|
commonGas = 192138
|
||||||
// testAddr is the Ethereum address of the tester account.
|
// testAddr is the Ethereum address of the tester account.
|
||||||
testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
|
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 is the test parameters array for specific blocks.
|
||||||
testBlocks = []testBlockParam{
|
testBlocks = []testBlockParam{
|
||||||
{
|
{
|
||||||
@ -175,16 +144,6 @@ type testBlockParam struct {
|
|||||||
txs []testTransactionParam
|
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
|
// testBackend is a mock implementation of the live Ethereum message handler. Its
|
||||||
// purpose is to allow testing the request/reply workflows and wire serialization
|
// purpose is to allow testing the request/reply workflows and wire serialization
|
||||||
// in the `eth` protocol without actually doing any data processing.
|
// 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)
|
bs, _ := GenerateChain(params.TestChainConfig, chain.Genesis(), ethash.NewFaker(), db, blocks, generator)
|
||||||
if _, err := chain.InsertChain(bs); err != nil {
|
if _, err := chain.InsertChain(bs); err != nil {
|
||||||
@ -271,21 +229,6 @@ func (b *testBackend) close() {
|
|||||||
|
|
||||||
func (b *testBackend) Chain() *BlockChain { return b.chain }
|
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) {
|
func TestFreezeDiffLayer(t *testing.T) {
|
||||||
blockNum := 1024
|
blockNum := 1024
|
||||||
fullBackend := newTestBackend(blockNum, true)
|
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)
|
bs1, _ := GenerateChain(params.TestChainConfig, chain1.Genesis(), ethash.NewFaker(), db1, len1, generator1)
|
||||||
if _, err := chain1.InsertChain(bs1); err != nil {
|
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
|
// Both header and body validation errors (nil too) is cached into the iterator
|
||||||
// to avoid duplicating work on the following next() call.
|
// to avoid duplicating work on the following next() call.
|
||||||
|
//
|
||||||
|
// nolint:unused
|
||||||
func (it *insertIterator) peek() (*types.Block, error) {
|
func (it *insertIterator) peek() (*types.Block, error) {
|
||||||
// If we reached the end of the chain, abort
|
// If we reached the end of the chain, abort
|
||||||
if it.index+1 >= len(it.chain) {
|
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.
|
// with various length chains.
|
||||||
func TestExtendCanonicalHeaders(t *testing.T) {
|
func TestExtendCanonicalHeaders(t *testing.T) {
|
||||||
testExtendCanonical(t, false, false)
|
testExtendCanonical(t, false, false)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendCanonicalBlocks(t *testing.T) {
|
func TestExtendCanonicalBlocks(t *testing.T) {
|
||||||
testExtendCanonical(t, true, false)
|
testExtendCanonical(t, true, false)
|
||||||
testExtendCanonical(t, true, true)
|
testExtendCanonical(t, true, true)
|
||||||
@ -452,7 +452,6 @@ func TestLongerForkHeaders(t *testing.T) {
|
|||||||
func TestLongerForkBlocks(t *testing.T) {
|
func TestLongerForkBlocks(t *testing.T) {
|
||||||
testLongerFork(t, true, false)
|
testLongerFork(t, true, false)
|
||||||
testLongerFork(t, true, true)
|
testLongerFork(t, true, true)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testLongerFork(t *testing.T, full, pipeline bool) {
|
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}
|
return ID{Hash: checksumToBytes(hash), Next: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NewIDWithChain calculates the Ethereum fork ID from an existing chain instance.
|
// NewIDWithChain calculates the Ethereum fork ID from an existing chain instance.
|
||||||
func NewIDWithChain(chain Blockchain) ID {
|
func NewIDWithChain(chain Blockchain) ID {
|
||||||
head := chain.CurrentHeader()
|
head := chain.CurrentHeader()
|
||||||
|
@ -159,7 +159,7 @@ func NewFreezer(datadir string, namespace string, readonly bool, offset uint64,
|
|||||||
// Create the write batch.
|
// Create the write batch.
|
||||||
freezer.writeBatch = newFreezerBatch(freezer)
|
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
|
return freezer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ func TestFreezerReadonlyValidate(t *testing.T) {
|
|||||||
|
|
||||||
// Re-openening as readonly should fail when validating
|
// Re-openening as readonly should fail when validating
|
||||||
// table lengths.
|
// table lengths.
|
||||||
f, err = NewFreezer(dir, "", true, 0, 2049, tables)
|
_, err = NewFreezer(dir, "", true, 0, 2049, tables)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("readonly freezer should fail with differing table lengths")
|
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 tracks the latest known incomplete block's hash during fast sync.
|
||||||
headFastBlockKey = []byte("LastFast")
|
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 tracks the id of latest stored state(for path-based only).
|
||||||
persistentStateIDKey = []byte("LastStateID")
|
persistentStateIDKey = []byte("LastStateID")
|
||||||
|
|
||||||
@ -70,9 +67,6 @@ var (
|
|||||||
// snapshotSyncStatusKey tracks the snapshot sync status across restarts.
|
// snapshotSyncStatusKey tracks the snapshot sync status across restarts.
|
||||||
snapshotSyncStatusKey = []byte("SnapshotSyncStatus")
|
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 tracks the in-memory trie node layers across restarts.
|
||||||
trieJournalKey = []byte("TrieJournal")
|
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.
|
// 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 {
|
func (p *BlockPruner) BlockPruneBackUp(name string, cache, handles int, namespace string, readonly, interrupt bool) error {
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
if err := p.backUpOldDb(name, cache, handles, namespace, readonly, interrupt); err != nil {
|
if err := p.backUpOldDb(name, cache, handles, namespace, readonly, interrupt); err != nil {
|
||||||
|
@ -192,7 +192,6 @@ func (p *triePrefetcher) mainLoop() {
|
|||||||
}
|
}
|
||||||
fetcher.lock.Unlock()
|
fetcher.lock.Unlock()
|
||||||
p.storageWasteMeter.Mark(int64(len(fetcher.seen)))
|
p.storageWasteMeter.Mark(int64(len(fetcher.seen)))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,6 @@ func (p *statePrefetcher) PrefetchMining(txs TransactionsByPriceAndNonce, header
|
|||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
if count++; count%checkInterval == 0 {
|
if count++; count%checkInterval == 0 {
|
||||||
|
|
||||||
txset.Forward(*txCurr)
|
txset.Forward(*txCurr)
|
||||||
}
|
}
|
||||||
tx := txset.PeekWithUnwrap()
|
tx := txset.PeekWithUnwrap()
|
||||||
|
@ -60,7 +60,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
// For contract upgrades, the following information is from `bsc-genesis-contract`, to be specifically,
|
// 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;
|
// 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`.
|
// 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()
|
pool.mu.RUnlock()
|
||||||
if len(reannoTxs) > 0 {
|
if len(reannoTxs) > 0 {
|
||||||
pool.reannoTxFeed.Send(core.ReannoTxsEvent{reannoTxs})
|
pool.reannoTxFeed.Send(core.ReannoTxsEvent{Txs: reannoTxs})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle local transaction journal rotation
|
// Handle local transaction journal rotation
|
||||||
@ -427,7 +427,6 @@ func (pool *LegacyPool) loop() {
|
|||||||
}
|
}
|
||||||
pool.mu.Unlock()
|
pool.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ type ConsensusState struct {
|
|||||||
// | chainID | height | appHash | curValidatorSetHash | [{validator pubkey, voting power}] |
|
// | chainID | height | appHash | curValidatorSetHash | [{validator pubkey, voting power}] |
|
||||||
// | 32 bytes | 8 bytes | 32 bytes | 32 bytes | [{32 bytes, 8 bytes}] |
|
// | 32 bytes | 8 bytes | 32 bytes | 32 bytes | [{32 bytes, 8 bytes}] |
|
||||||
func DecodeConsensusState(input []byte) (ConsensusState, error) {
|
func DecodeConsensusState(input []byte) (ConsensusState, error) {
|
||||||
|
|
||||||
minimumLength := chainIDLength + heightLength + appHashLength + validatorSetHashLength
|
minimumLength := chainIDLength + heightLength + appHashLength + validatorSetHashLength
|
||||||
singleValidatorBytesLength := validatorPubkeyLength + validatorVotingPowerLength
|
singleValidatorBytesLength := validatorPubkeyLength + validatorVotingPowerLength
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -415,7 +414,7 @@ func setUpKeyManager(t *testing.T) (string, string) {
|
|||||||
if err := os.MkdirAll(filepath.Dir(walletPasswordDir), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(walletPasswordDir), 0700); err != nil {
|
||||||
t.Fatalf("failed to create walletPassword dir: %v", err)
|
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)
|
t.Fatalf("failed to write wallet password dir: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package vote
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -41,7 +41,7 @@ func NewVoteSigner(blsPasswordPath, blsWalletPath string) (*VoteSigner, error) {
|
|||||||
return nil, fmt.Errorf("BLS wallet did not exists")
|
return nil, fmt.Errorf("BLS wallet did not exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
walletPassword, err := ioutil.ReadFile(blsPasswordPath)
|
walletPassword, err := os.ReadFile(blsPasswordPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Read BLS wallet password", "err", err)
|
log.Error("Read BLS wallet password", "err", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -199,9 +199,8 @@ func miller(q *twistPoint, p *curvePoint) *gfP12 {
|
|||||||
r = newR
|
r = newR
|
||||||
|
|
||||||
r2.Square(&minusQ2.y)
|
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)
|
mulLine(ret, a, b, c)
|
||||||
r = newR
|
|
||||||
|
|
||||||
return ret
|
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
|
MaxReceiptFetch = 256 // Amount of transaction receipts to allow fetching per request
|
||||||
MaxStateFetch = 384 // Amount of node state values 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)
|
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
|
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
|
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.
|
// peerDropFn is a callback type for dropping a peer detected as malicious.
|
||||||
type peerDropFn func(id string)
|
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
|
// headerTask is a set of downloaded headers to queue along with their precomputed
|
||||||
// hashes to avoid constant rehashing.
|
// hashes to avoid constant rehashing.
|
||||||
type headerTask struct {
|
type headerTask struct {
|
||||||
@ -120,7 +113,6 @@ type Downloader struct {
|
|||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
dropPeer peerDropFn // Drops a peer for misbehaving
|
dropPeer peerDropFn // Drops a peer for misbehaving
|
||||||
badBlock badBlockFn // Reports a block as rejected by the chain
|
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
synchroniseMock func(id string, hash common.Hash) error // Replacement for synchronise during testing
|
synchroniseMock func(id string, hash common.Hash) error // Replacement for synchronise during testing
|
||||||
@ -783,14 +775,16 @@ func (d *Downloader) findAncestor(p *peerConnection, localHeight uint64, remoteH
|
|||||||
remoteHeight = remoteHeader.Number.Uint64()
|
remoteHeight = remoteHeader.Number.Uint64()
|
||||||
)
|
)
|
||||||
mode := d.getMode()
|
mode := d.getMode()
|
||||||
switch mode {
|
/*
|
||||||
case FullSync:
|
switch mode {
|
||||||
localHeight = d.blockchain.CurrentBlock().Number.Uint64()
|
case FullSync:
|
||||||
case SnapSync:
|
localHeight = d.blockchain.CurrentBlock().Number.Uint64()
|
||||||
localHeight = d.blockchain.CurrentSnapBlock().Number.Uint64()
|
case SnapSync:
|
||||||
default:
|
localHeight = d.blockchain.CurrentSnapBlock().Number.Uint64()
|
||||||
localHeight = d.lightchain.CurrentHeader().Number.Uint64()
|
default:
|
||||||
}
|
localHeight = d.lightchain.CurrentHeader().Number.Uint64()
|
||||||
|
}
|
||||||
|
*/
|
||||||
p.log.Debug("Looking for common ancestor", "local", localHeight, "remote", remoteHeight)
|
p.log.Debug("Looking for common ancestor", "local", localHeight, "remote", remoteHeight)
|
||||||
|
|
||||||
// Recap floor value for binary search
|
// 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.
|
// reportSnapSyncProgress calculates various status reports and provides it to the user.
|
||||||
func (d *Downloader) reportSnapSyncProgress(force bool) {
|
func (d *Downloader) reportSnapSyncProgress(force bool) {
|
||||||
// Initialize the sync start time if it's the first time we're reporting
|
// 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() {
|
gopool.Submit(func() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case logs := <-matchedLogs:
|
case logs := <-matchedLogs:
|
||||||
|
@ -190,17 +190,16 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type subscription struct {
|
type subscription struct {
|
||||||
id rpc.ID
|
id rpc.ID
|
||||||
typ Type
|
typ Type
|
||||||
created time.Time
|
created time.Time
|
||||||
logsCrit ethereum.FilterQuery
|
logsCrit ethereum.FilterQuery
|
||||||
logs chan []*types.Log
|
logs chan []*types.Log
|
||||||
txs chan []*types.Transaction
|
txs chan []*types.Transaction
|
||||||
headers chan *types.Header
|
headers chan *types.Header
|
||||||
finalizedHeaders chan *types.Header
|
votes chan *types.VoteEnvelope
|
||||||
votes chan *types.VoteEnvelope
|
installed chan struct{} // closed when the filter is installed
|
||||||
installed chan struct{} // closed when the filter is installed
|
err chan error // closed when the filter is uninstalled
|
||||||
err chan error // closed when the filter is uninstalled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EventSystem creates subscriptions, processes events and broadcasts them to the
|
// EventSystem creates subscriptions, processes events and broadcasts them to the
|
||||||
|
@ -43,7 +43,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type testBackend struct {
|
type testBackend struct {
|
||||||
mux *event.TypeMux
|
|
||||||
db ethdb.Database
|
db ethdb.Database
|
||||||
sections uint64
|
sections uint64
|
||||||
txFeed event.Feed
|
txFeed event.Feed
|
||||||
|
@ -161,7 +161,6 @@ func testSendVotes(t *testing.T, protocol uint) {
|
|||||||
t.Errorf("missing vote: %x", vote.Hash())
|
t.Errorf("missing vote: %x", vote.Hash())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRecvVotes67(t *testing.T) { testRecvVotes(t, eth.ETH67) }
|
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)
|
tryFunc(tryNum, "[2001:db8::11]:", "[2001:db8::22]:", true, doneCh5)
|
||||||
}
|
}
|
||||||
close(doneCh5)
|
close(doneCh5)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
package eth
|
package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/eth/protocols/bsc"
|
"github.com/ethereum/go-ethereum/eth/protocols/bsc"
|
||||||
"github.com/ethereum/go-ethereum/eth/protocols/trust"
|
"github.com/ethereum/go-ethereum/eth/protocols/trust"
|
||||||
|
|
||||||
@ -38,9 +36,6 @@ type ethPeer struct {
|
|||||||
snapExt *snapPeer // Satellite `snap` connection
|
snapExt *snapPeer // Satellite `snap` connection
|
||||||
trustExt *trustPeer
|
trustExt *trustPeer
|
||||||
bscExt *bscPeer // Satellite `bsc` connection
|
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.
|
// 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",
|
return nil, nil, fmt.Errorf("stateAtBlock commit failed, number %d root %v: %w",
|
||||||
current.NumberU64(), current.Root().Hex(), err)
|
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 {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("state reset after block %d failed: %v", current.NumberU64(), err)
|
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
|
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 {
|
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)
|
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
|
return backend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:unused
|
||||||
func (b *testBackend) setPendingBlock(block *types.Block) {
|
func (b *testBackend) setPendingBlock(block *types.Block) {
|
||||||
b.pending = block
|
b.pending = block
|
||||||
}
|
}
|
||||||
|
@ -846,7 +846,6 @@ type generateParams struct {
|
|||||||
coinbase common.Address // The fee recipient address for including transaction
|
coinbase common.Address // The fee recipient address for including transaction
|
||||||
random common.Hash // The randomness generated by beacon chain, empty before the merge
|
random common.Hash // The randomness generated by beacon chain, empty before the merge
|
||||||
withdrawals types.Withdrawals // List of withdrawals to include in block.
|
withdrawals types.Withdrawals // List of withdrawals to include in block.
|
||||||
noExtra bool // Flag whether the extra field assignment is allowed
|
|
||||||
prevWork *environment
|
prevWork *environment
|
||||||
noTxs bool // Flag whether an empty block without any transaction is expected
|
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 {
|
type StateTrie struct {
|
||||||
trie Trie
|
trie Trie
|
||||||
preimages *preimageStore
|
preimages *preimageStore
|
||||||
hashKeyBuf [common.HashLength]byte
|
hashKeyBuf [common.HashLength]byte //nolint:unused
|
||||||
secKeyCache map[string][]byte
|
secKeyCache map[string][]byte
|
||||||
secKeyCacheOwner *StateTrie // Pointer to self, replace the key cache on mismatch
|
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.
|
// hashKey returns the hash of key as an ephemeral buffer.
|
||||||
// The caller must not hold onto the return value because it will become
|
// The caller must not hold onto the return value because it will become
|
||||||
// invalid on the next call to hashKey or secKey.
|
// invalid on the next call to hashKey or secKey.
|
||||||
|
//
|
||||||
|
// no use hashKeyBuf for thread safe.
|
||||||
func (t *StateTrie) hashKey(key []byte) []byte {
|
func (t *StateTrie) hashKey(key []byte) []byte {
|
||||||
hash := make([]byte, common.HashLength)
|
hash := make([]byte, common.HashLength)
|
||||||
h := newHasher(false)
|
h := newHasher(false)
|
||||||
|
Loading…
Reference in New Issue
Block a user