mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
* Adding in Mumbai/Mainnet precursor deb packaging for tests to use during upgrade(iterations to come) * Added changes per discussion in PR, more changes may be necessary * Adding prerelease true * Disabling goreleaser * Removing README swap file * change bor_dir and add bor user for v0.3.0 release * rollback bor user and use root * metrics: handle equal to separated config flag (#596) * metrics: handle based config path * internal/cli/server: add more context to logs * use space separated flag and value in bor.service * fixed static-nodes related buf (os independent) (#598) * fixed static-nodes related buf (os independent) * taking static-nodes as input if default not present * Update default flags (#600) * internal/cli/server: use geth's default for txpool.pricelimit and add comments * builder/files: update config.toml for mainnet * packaging/templates: update defaults for mainnet and mumbai * internal/cli/server: skip overriding cache * packaging/templates: update cache value for mainnet * packaging/templates: update gcmode for archive mumbai node * metrics: handle nil telemetry config (#601) * resolve merge conflicts * update go version in release.yml * update goversion in makefile * update Docker login for goreleaser-cross v1.19 * Cleanup for the packager to use git tag in the package profile naming. Added conditional check for directory structure, this is in prep for v0.3.1, as this will create a failure on upgrade path in package due to file exist * added a toml configuration file with comments describing each flag (#607) * added a toml configuration file with comments describing each flag * internal/cli/server: update flag description * docs/cli: update example config and description of flags * docs: update new-cli docs Co-authored-by: Manav Darji <manavdarji.india@gmail.com> * Adding of 0.3.0 package changes, control file updates, postinst changes, and packager update * added ancient datadir flag and toml field, need to decide on default value and update the conversion script * updated toml files with ancient field * Add support for new flags in new config.toml, which were present in old config.toml (#612) * added HTTPTimeouts, and TrieTimeout flag in new tol, from old toml * added RAW fields for these time.Duration flags * updated the conversion script to support these extra 4 flags * removed hcl and json config tests as we are only supporting toml config files * updated toml files with cache.timeout field * updated toml files with jsonrpc.timeouts field * tests/bor: expect a call for latest checkpoint * tests/bor: expect a call for latest checkpoint * packaging/templates: update cache values for archive nodes Co-authored-by: Manav Darji <manavdarji.india@gmail.com> * remove unwanted code * Fix docker publish authentication issue In gorelease-cross 1.19+, dockerhub authentication will require docker logion action followed by mounting docker config file. See https://github.com/goreleaser/goreleaser-cross#github-actions. * Revert "update Docker login for goreleaser-cross v1.19" This reverts commit4d19cf5342. * Bump version to stable * Revert "Merge pull request #435 from maticnetwork/POS-553" This reverts commit657d262def, reversing changes made to88dbfa1c13. * revert change for release for go1.19 * Add default values to CLI helper and docs This commit adds default values to CLI helper and docs. When the default value of a string flag, slice string flag, or map string flag is empty, its helper message won't show any default value. * Add a summary of new CLI in docs * Updating packager as binutils changed version so that apt-get installs current versions * Add state pruning to new CLI * Minor wording fix in prune state description * Bumping control file versions * Mainnet Delhi fork * Set version to stable * change delhi hardfork block number * handle future chain import and skip peer drop (#650) * handle future chain import and skip peer drop * add block import metric * params: bump version to v0.3.3-stable * Bump bor version in control files for v0.3.3 mainnet release Co-authored-by: Daniel Jones <djones@polygon.technology> Co-authored-by: Will Button <wbutton@polygon.technology> Co-authored-by: Will Button <will@willbutton.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Daniel Jones <105369507+djpolygon@users.noreply.github.com> Co-authored-by: Pratik Patil <pratikspatil024@gmail.com> Co-authored-by: Arpit Temani <temaniarpit27@gmail.com> Co-authored-by: Jerry <jerrycgh@gmail.com>
240 lines
8.2 KiB
Go
240 lines
8.2 KiB
Go
package core
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/params"
|
|
)
|
|
|
|
// chainValidatorFake is a mock for the chain validator service
|
|
type chainValidatorFake struct {
|
|
validate func(currentHeader *types.Header, chain []*types.Header) (bool, error)
|
|
}
|
|
|
|
// chainReaderFake is a mock for the chain reader service
|
|
type chainReaderFake struct {
|
|
getTd func(hash common.Hash, number uint64) *big.Int
|
|
}
|
|
|
|
func newChainValidatorFake(validate func(currentHeader *types.Header, chain []*types.Header) (bool, error)) *chainValidatorFake {
|
|
return &chainValidatorFake{validate: validate}
|
|
}
|
|
|
|
func newChainReaderFake(getTd func(hash common.Hash, number uint64) *big.Int) *chainReaderFake {
|
|
return &chainReaderFake{getTd: getTd}
|
|
}
|
|
|
|
func TestPastChainInsert(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var (
|
|
db = rawdb.NewMemoryDatabase()
|
|
genesis = (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db)
|
|
)
|
|
|
|
hc, err := NewHeaderChain(db, params.AllEthashProtocolChanges, ethash.NewFaker(), func() bool { return false })
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Create mocks for forker
|
|
getTd := func(hash common.Hash, number uint64) *big.Int {
|
|
return big.NewInt(int64(number))
|
|
}
|
|
validate := func(currentHeader *types.Header, chain []*types.Header) (bool, error) {
|
|
// Put all explicit conditions here
|
|
// If canonical chain is empty and we're importing a chain of 64 blocks
|
|
if currentHeader.Number.Uint64() == uint64(0) && len(chain) == 64 {
|
|
return true, nil
|
|
}
|
|
// If canonical chain is of len 64 and we're importing a past chain from 54-64, then accept it
|
|
if currentHeader.Number.Uint64() == uint64(64) && chain[0].Number.Uint64() == 55 && len(chain) == 10 {
|
|
return true, nil
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
mockChainReader := newChainReaderFake(getTd)
|
|
mockChainValidator := newChainValidatorFake(validate)
|
|
mockForker := NewForkChoice(mockChainReader, nil, mockChainValidator)
|
|
|
|
// chain A: G->A1->A2...A64
|
|
chainA := makeHeaderChain(genesis.Header(), 64, ethash.NewFaker(), db, 10)
|
|
|
|
// Inserting 64 headers on an empty chain
|
|
// expecting 1 write status with no error
|
|
testInsert(t, hc, chainA, CanonStatTy, nil, mockForker)
|
|
|
|
// The current chain is: G->A1->A2...A64
|
|
// chain B: G->A1->A2...A44->B45->B46...B64
|
|
chainB := makeHeaderChain(chainA[43], 20, ethash.NewFaker(), db, 10)
|
|
|
|
// The current chain is: G->A1->A2...A64
|
|
// chain C: G->A1->A2...A54->C55->C56...C64
|
|
chainC := makeHeaderChain(chainA[53], 10, ethash.NewFaker(), db, 10)
|
|
|
|
// Update the function to consider chainC with higher difficulty
|
|
getTd = func(hash common.Hash, number uint64) *big.Int {
|
|
td := big.NewInt(int64(number))
|
|
if hash == chainB[len(chainB)-1].Hash() || hash == chainC[len(chainC)-1].Hash() {
|
|
td = big.NewInt(65)
|
|
}
|
|
|
|
return td
|
|
}
|
|
mockChainReader = newChainReaderFake(getTd)
|
|
mockForker = NewForkChoice(mockChainReader, nil, mockChainValidator)
|
|
|
|
// Inserting 20 blocks from chainC on canonical chain
|
|
// expecting 2 write status with no error
|
|
testInsert(t, hc, chainB, SideStatTy, nil, mockForker)
|
|
|
|
// Inserting 10 blocks from chainB on canonical chain
|
|
// expecting 1 write status with no error
|
|
testInsert(t, hc, chainC, CanonStatTy, nil, mockForker)
|
|
}
|
|
|
|
func TestFutureChainInsert(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var (
|
|
db = rawdb.NewMemoryDatabase()
|
|
genesis = (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db)
|
|
)
|
|
|
|
hc, err := NewHeaderChain(db, params.AllEthashProtocolChanges, ethash.NewFaker(), func() bool { return false })
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Create mocks for forker
|
|
getTd := func(hash common.Hash, number uint64) *big.Int {
|
|
return big.NewInt(int64(number))
|
|
}
|
|
validate := func(currentHeader *types.Header, chain []*types.Header) (bool, error) {
|
|
// Put all explicit conditions here
|
|
// If canonical chain is empty and we're importing a chain of 64 blocks
|
|
if currentHeader.Number.Uint64() == uint64(0) && len(chain) == 64 {
|
|
return true, nil
|
|
}
|
|
// If length of future chains > some value, they should not be accepted
|
|
if currentHeader.Number.Uint64() == uint64(64) && len(chain) <= 10 {
|
|
return true, nil
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
mockChainReader := newChainReaderFake(getTd)
|
|
mockChainValidator := newChainValidatorFake(validate)
|
|
mockForker := NewForkChoice(mockChainReader, nil, mockChainValidator)
|
|
|
|
// chain A: G->A1->A2...A64
|
|
chainA := makeHeaderChain(genesis.Header(), 64, ethash.NewFaker(), db, 10)
|
|
|
|
// Inserting 64 headers on an empty chain
|
|
// expecting 1 write status with no error
|
|
testInsert(t, hc, chainA, CanonStatTy, nil, mockForker)
|
|
|
|
// The current chain is: G->A1->A2...A64
|
|
// chain B: G->A1->A2...A64->B65->B66...B84
|
|
chainB := makeHeaderChain(chainA[63], 20, ethash.NewFaker(), db, 10)
|
|
|
|
// Inserting 20 headers on the canonical chain
|
|
// expecting 0 write status with no error
|
|
testInsert(t, hc, chainB, SideStatTy, nil, mockForker)
|
|
|
|
// The current chain is: G->A1->A2...A64
|
|
// chain C: G->A1->A2...A64->C65->C66...C74
|
|
chainC := makeHeaderChain(chainA[63], 10, ethash.NewFaker(), db, 10)
|
|
|
|
// Inserting 10 headers on the canonical chain
|
|
// expecting 0 write status with no error
|
|
testInsert(t, hc, chainC, CanonStatTy, nil, mockForker)
|
|
}
|
|
|
|
func TestOverlappingChainInsert(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var (
|
|
db = rawdb.NewMemoryDatabase()
|
|
genesis = (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db)
|
|
)
|
|
|
|
hc, err := NewHeaderChain(db, params.AllEthashProtocolChanges, ethash.NewFaker(), func() bool { return false })
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Create mocks for forker
|
|
getTd := func(hash common.Hash, number uint64) *big.Int {
|
|
return big.NewInt(int64(number))
|
|
}
|
|
validate := func(currentHeader *types.Header, chain []*types.Header) (bool, error) {
|
|
// Put all explicit conditions here
|
|
// If canonical chain is empty and we're importing a chain of 64 blocks
|
|
if currentHeader.Number.Uint64() == uint64(0) && len(chain) == 64 {
|
|
return true, nil
|
|
}
|
|
// If length of chain is > some fixed value then don't accept it
|
|
if currentHeader.Number.Uint64() == uint64(64) && len(chain) <= 20 {
|
|
return true, nil
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
mockChainReader := newChainReaderFake(getTd)
|
|
mockChainValidator := newChainValidatorFake(validate)
|
|
mockForker := NewForkChoice(mockChainReader, nil, mockChainValidator)
|
|
|
|
// chain A: G->A1->A2...A64
|
|
chainA := makeHeaderChain(genesis.Header(), 64, ethash.NewFaker(), db, 10)
|
|
|
|
// Inserting 64 headers on an empty chain
|
|
// expecting 1 write status with no error
|
|
testInsert(t, hc, chainA, CanonStatTy, nil, mockForker)
|
|
|
|
// The current chain is: G->A1->A2...A64
|
|
// chain B: G->A1->A2...A54->B55->B56...B84
|
|
chainB := makeHeaderChain(chainA[53], 30, ethash.NewFaker(), db, 10)
|
|
|
|
// Inserting 20 blocks on canonical chain
|
|
// expecting 2 write status with no error
|
|
testInsert(t, hc, chainB, SideStatTy, nil, mockForker)
|
|
|
|
// The current chain is: G->A1->A2...A64
|
|
// chain C: G->A1->A2...A54->C55->C56...C74
|
|
chainC := makeHeaderChain(chainA[53], 20, ethash.NewFaker(), db, 10)
|
|
|
|
// Inserting 10 blocks on canonical chain
|
|
// expecting 1 write status with no error
|
|
testInsert(t, hc, chainC, CanonStatTy, nil, mockForker)
|
|
}
|
|
|
|
// Mock chain reader functions
|
|
func (c *chainReaderFake) Config() *params.ChainConfig {
|
|
return ¶ms.ChainConfig{TerminalTotalDifficulty: nil}
|
|
}
|
|
func (c *chainReaderFake) GetTd(hash common.Hash, number uint64) *big.Int {
|
|
return c.getTd(hash, number)
|
|
}
|
|
|
|
// Mock chain validator functions
|
|
func (w *chainValidatorFake) IsValidPeer(remoteHeader *types.Header, fetchHeadersByNumber func(number uint64, amount int, skip int, reverse bool) ([]*types.Header, []common.Hash, error)) (bool, error) {
|
|
return true, nil
|
|
}
|
|
func (w *chainValidatorFake) IsValidChain(current *types.Header, headers []*types.Header) (bool, error) {
|
|
return w.validate(current, headers)
|
|
}
|
|
func (w *chainValidatorFake) ProcessCheckpoint(endBlockNum uint64, endBlockHash common.Hash) {}
|
|
func (w *chainValidatorFake) GetCheckpointWhitelist() map[uint64]common.Hash {
|
|
return nil
|
|
}
|
|
func (w *chainValidatorFake) PurgeCheckpointWhitelist() {}
|
|
func (w *chainValidatorFake) GetCheckpoints(current, sidechainHeader *types.Header, sidechainCheckpoints []*types.Header) (map[uint64]*types.Header, error) {
|
|
return map[uint64]*types.Header{}, nil
|
|
}
|