diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go
index c3b41bf182..16c8808360 100644
--- a/cmd/evm/internal/t8ntool/execution.go
+++ b/cmd/evm/internal/t8ntool/execution.go
@@ -368,7 +368,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
}
// Commit block
- root, _, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber), chainConfig.IsCancun(vmContext.BlockNumber, vmContext.Time))
+ root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber), chainConfig.IsCancun(vmContext.BlockNumber, vmContext.Time))
if err != nil {
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not commit state: %v", err))
}
@@ -426,7 +426,7 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB
}
}
// Commit and re-open to start with a clean state.
- root, _, _ := statedb.Commit(0, false, false)
+ root, _ := statedb.Commit(0, false, false)
statedb, _ = state.New(root, sdb)
return statedb
}
diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go
index 4811d2e8d9..b2cf28353b 100644
--- a/cmd/evm/runner.go
+++ b/cmd/evm/runner.go
@@ -336,7 +336,7 @@ func runCmd(ctx *cli.Context) error {
output, stats, err := timedExec(bench, execFunc)
if ctx.Bool(DumpFlag.Name) {
- root, _, err := runtimeConfig.State.Commit(genesisConfig.Number, true, false)
+ root, err := runtimeConfig.State.Commit(genesisConfig.Number, true, false)
if err != nil {
fmt.Printf("Failed to commit changes %v\n", err)
return err
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 58e5eb58cb..4f5cf5630e 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -68,7 +68,6 @@ var (
utils.NoUSBFlag, // deprecated
utils.DirectBroadcastFlag,
utils.DisableSnapProtocolFlag,
- utils.EnableTrustProtocolFlag,
utils.RangeLimitFlag,
utils.USBFlag,
utils.SmartCardDaemonPathFlag,
@@ -132,8 +131,6 @@ var (
// utils.CacheNoPrefetchFlag,
utils.CachePreimagesFlag,
utils.MultiDataBaseFlag,
- utils.PersistDiffFlag,
- utils.DiffBlockFlag,
utils.PruneAncientDataFlag,
utils.CacheLogSizeFlag,
utils.FDLimitFlag,
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 44c6b409ba..605047b455 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -113,21 +113,11 @@ var (
Usage: "Disable snap protocol",
Category: flags.EthCategory,
}
- EnableTrustProtocolFlag = &cli.BoolFlag{
- Name: "enabletrustprotocol",
- Usage: "Enable trust protocol",
- Category: flags.FastNodeCategory,
- }
RangeLimitFlag = &cli.BoolFlag{
Name: "rangelimit",
Usage: "Enable 5000 blocks limit for range query",
Category: flags.APICategory,
}
- DiffFlag = flags.DirectoryFlag{
- Name: "datadir.diff",
- Usage: "Data directory for difflayer segments (default = inside chaindata)",
- Category: flags.FastNodeCategory,
- }
RemoteDBFlag = &cli.StringFlag{
Name: "remotedb",
Usage: "URL for remote database",
@@ -282,9 +272,6 @@ var (
Usage: `tries verify mode:
"local(default): a normal full node with complete state world(both MPT and snapshot), merkle state root will
be verified against the block header.",
- "full: a fast node with only snapshot state world. Merkle state root is verified by the trustworthy remote verify node
- by comparing the diffhash(an identify of difflayer generated by the block) and state root.",
- "insecure: same as full mode, except that it can tolerate without verifying the diffhash when verify node does not have it.",
"none: no merkle state root verification at all, there is no need to setup or connect remote verify node at all,
it is more light comparing to full and insecure mode, but get a very small chance that the state is not consistent
with other peers."`,
@@ -581,17 +568,6 @@ var (
Usage: "Enable recording the SHA3/keccak preimages of trie keys",
Category: flags.PerfCategory,
}
- PersistDiffFlag = &cli.BoolFlag{
- Name: "persistdiff",
- Usage: "Enable persistence of the diff layer",
- Category: flags.FastNodeCategory,
- }
- DiffBlockFlag = &cli.Uint64Flag{
- Name: "diffblock",
- Usage: "The number of blocks should be persisted in db (default = 86400)",
- Value: uint64(86400),
- Category: flags.FastNodeCategory,
- }
PruneAncientDataFlag = &cli.BoolFlag{
Name: "pruneancient",
Usage: "Prune ancient data, is an optional config and disabled by default. Only keep the latest 9w blocks' data,the older blocks' data will be permanently pruned. Notice:the geth/chaindata/ancient dir will be removed, if restart without the flag, the ancient data will start with the previous point that the oldest unpruned block number. Recommends to the user who don't care about the ancient data.",
@@ -2060,15 +2036,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(AncientFlag.Name) {
cfg.DatabaseFreezer = ctx.String(AncientFlag.Name)
}
- if ctx.IsSet(DiffFlag.Name) {
- cfg.DatabaseDiff = ctx.String(DiffFlag.Name)
- }
- if ctx.IsSet(PersistDiffFlag.Name) {
- cfg.PersistDiff = ctx.Bool(PersistDiffFlag.Name)
- }
- if ctx.IsSet(DiffBlockFlag.Name) {
- cfg.DiffBlock = ctx.Uint64(DiffBlockFlag.Name)
- }
if ctx.IsSet(PruneAncientDataFlag.Name) {
if cfg.SyncMode != ethconfig.FullSync {
log.Warn("pruneancient parameter can only be used with syncmode=full, force to full sync")
@@ -2088,9 +2055,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(DisableSnapProtocolFlag.Name) {
cfg.DisableSnapProtocol = ctx.Bool(DisableSnapProtocolFlag.Name)
}
- if ctx.IsSet(EnableTrustProtocolFlag.Name) {
- cfg.EnableTrustProtocol = ctx.IsSet(EnableTrustProtocolFlag.Name)
- }
if ctx.IsSet(RangeLimitFlag.Name) {
cfg.RangeLimit = ctx.Bool(RangeLimitFlag.Name)
}
@@ -2150,11 +2114,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if err = cfg.TriesVerifyMode.UnmarshalText([]byte(ctx.String(TriesVerifyModeFlag.Name))); err != nil {
Fatalf("invalid --tries-verify-mode flag: %v", err)
}
- // If a node sets verify mode to full or insecure, it's a fast node and need
- // to verify blocks from verify nodes, then it should enable trust protocol.
- if cfg.TriesVerifyMode.NeedRemoteVerify() {
- cfg.EnableTrustProtocol = true
- }
// A node without trie is not able to provide snap data, so it should disable snap protocol.
if cfg.TriesVerifyMode != core.LocalVerify {
log.Info("Automatically disables snap protocol due to verify mode", "mode", cfg.TriesVerifyMode)
@@ -2207,7 +2166,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.RPCTxFeeCap = ctx.Float64(RPCGlobalTxFeeCapFlag.Name)
}
if ctx.IsSet(NoDiscoverFlag.Name) {
- cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs, cfg.TrustDiscoveryURLs, cfg.BscDiscoveryURLs = []string{}, []string{}, []string{}, []string{}
+ cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs, cfg.BscDiscoveryURLs = []string{}, []string{}, []string{}
} else if ctx.IsSet(DNSDiscoveryFlag.Name) {
urls := ctx.String(DNSDiscoveryFlag.Name)
if urls == "" {
@@ -2356,7 +2315,6 @@ func SetDNSDiscoveryDefaults(cfg *ethconfig.Config, genesis common.Hash) {
if url := params.KnownDNSNetwork(genesis, protocol); url != "" {
cfg.EthDiscoveryURLs = []string{url}
cfg.SnapDiscoveryURLs = cfg.EthDiscoveryURLs
- cfg.TrustDiscoveryURLs = cfg.EthDiscoveryURLs
cfg.BscDiscoveryURLs = cfg.EthDiscoveryURLs
}
}
diff --git a/core/block_validator.go b/core/block_validator.go
index 066b2111af..49e58c8cb6 100644
--- a/core/block_validator.go
+++ b/core/block_validator.go
@@ -27,36 +27,22 @@ import (
"github.com/ethereum/go-ethereum/trie"
)
-type BlockValidatorOption func(*BlockValidator) *BlockValidator
-
-func EnableRemoteVerifyManager(remoteValidator *remoteVerifyManager) BlockValidatorOption {
- return func(bv *BlockValidator) *BlockValidator {
- bv.remoteValidator = remoteValidator
- return bv
- }
-}
-
// BlockValidator is responsible for validating block headers, uncles and
// processed state.
//
// BlockValidator implements Validator.
type BlockValidator struct {
- config *params.ChainConfig // Chain configuration options
- bc *BlockChain // Canonical block chain
- remoteValidator *remoteVerifyManager
+ config *params.ChainConfig // Chain configuration options
+ bc *BlockChain // Canonical block chain
}
// NewBlockValidator returns a new block validator which is safe for re-use
-func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, opts ...BlockValidatorOption) *BlockValidator {
+func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain) *BlockValidator {
validator := &BlockValidator{
config: config,
bc: blockchain,
}
- for _, opt := range opts {
- validator = opt(validator)
- }
-
return validator
}
@@ -135,12 +121,6 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
}
return nil
},
- func() error {
- if v.remoteValidator != nil && !v.remoteValidator.AncestorVerified(block.Header()) {
- return fmt.Errorf("%w, number: %s, hash: %s", ErrAncestorHasNotBeenVerified, block.Number(), block.Hash())
- }
- return nil
- },
}
validateRes := make(chan error, len(validateFuns))
for _, f := range validateFuns {
@@ -220,10 +200,6 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
return err
}
-func (v *BlockValidator) RemoteVerifyManager() *remoteVerifyManager {
- return v.remoteValidator
-}
-
// CalcGasLimit computes the gas limit of the next block after parent. It aims
// to keep the baseline gas close to the provided target, and increase it towards
// the target if the baseline gas is lower.
diff --git a/core/blockchain.go b/core/blockchain.go
index 6a497a7f08..d2f2f3e7d4 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -24,7 +24,6 @@ import (
"math/big"
"runtime"
"slices"
- "sort"
"sync"
"sync/atomic"
"time"
@@ -56,7 +55,6 @@ import (
"github.com/ethereum/go-ethereum/triedb"
"github.com/ethereum/go-ethereum/triedb/hashdb"
"github.com/ethereum/go-ethereum/triedb/pathdb"
- "golang.org/x/crypto/sha3"
)
var (
@@ -113,7 +111,6 @@ var (
const (
bodyCacheLimit = 256
blockCacheLimit = 256
- diffLayerCacheLimit = 1024
receiptsCacheLimit = 10000
sidecarsCacheLimit = 1024
txLookupCacheLimit = 1024
@@ -122,9 +119,6 @@ const (
maxBeyondBlocks = 2048
prefetchTxNumber = 100
- diffLayerFreezerRecheckInterval = 3 * time.Second
- maxDiffForkDist = 11 // Maximum allowed backward distance from the chain head
-
// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
//
// Changelog:
@@ -317,13 +311,6 @@ type BlockChain struct {
// future blocks are blocks added for later processing
futureBlocks *lru.Cache[common.Hash, *types.Block]
- // trusted diff layers
- diffLayerCache *lru.Cache[common.Hash, *types.DiffLayer] // Cache for the diffLayers
- diffLayerChanCache *lru.Cache[common.Hash, chan struct{}] // Cache for the difflayer channel
- diffQueue *prque.Prque[int64, *types.DiffLayer] // A Priority queue to store recent diff layer
- diffQueueBuffer chan *types.DiffLayer
- diffLayerFreezerBlockLimit uint64
-
wg sync.WaitGroup
dbWg sync.WaitGroup
quit chan struct{} // shutdown signal, closed in Stop.
@@ -384,29 +371,25 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
*/
bc := &BlockChain{
- chainConfig: chainConfig,
- cacheConfig: cacheConfig,
- db: db,
- triedb: triedb,
- triegc: prque.New[int64, common.Hash](nil),
- quit: make(chan struct{}),
- triesInMemory: cacheConfig.TriesInMemory,
- chainmu: syncx.NewClosableMutex(),
- bodyCache: lru.NewCache[common.Hash, *types.Body](bodyCacheLimit),
- bodyRLPCache: lru.NewCache[common.Hash, rlp.RawValue](bodyCacheLimit),
- receiptsCache: lru.NewCache[common.Hash, []*types.Receipt](receiptsCacheLimit),
- sidecarsCache: lru.NewCache[common.Hash, types.BlobSidecars](sidecarsCacheLimit),
- blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit),
- blockStatsCache: lru.NewCache[common.Hash, *BlockStats](blockCacheLimit),
- txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit),
- futureBlocks: lru.NewCache[common.Hash, *types.Block](maxFutureBlocks),
- diffLayerCache: lru.NewCache[common.Hash, *types.DiffLayer](diffLayerCacheLimit),
- diffLayerChanCache: lru.NewCache[common.Hash, chan struct{}](diffLayerCacheLimit),
- engine: engine,
- vmConfig: vmConfig,
- diffQueue: prque.New[int64, *types.DiffLayer](nil),
- diffQueueBuffer: make(chan *types.DiffLayer),
- logger: vmConfig.Tracer,
+ chainConfig: chainConfig,
+ cacheConfig: cacheConfig,
+ db: db,
+ triedb: triedb,
+ triegc: prque.New[int64, common.Hash](nil),
+ quit: make(chan struct{}),
+ triesInMemory: cacheConfig.TriesInMemory,
+ chainmu: syncx.NewClosableMutex(),
+ bodyCache: lru.NewCache[common.Hash, *types.Body](bodyCacheLimit),
+ bodyRLPCache: lru.NewCache[common.Hash, rlp.RawValue](bodyCacheLimit),
+ receiptsCache: lru.NewCache[common.Hash, []*types.Receipt](receiptsCacheLimit),
+ sidecarsCache: lru.NewCache[common.Hash, types.BlobSidecars](sidecarsCacheLimit),
+ blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit),
+ blockStatsCache: lru.NewCache[common.Hash, *BlockStats](blockCacheLimit),
+ txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit),
+ futureBlocks: lru.NewCache[common.Hash, *types.Block](maxFutureBlocks),
+ engine: engine,
+ vmConfig: vmConfig,
+ logger: vmConfig.Tracer,
}
bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.insertStopped)
if err != nil {
@@ -580,12 +563,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
bc.wg.Add(1)
go bc.updateFutureBlocks()
- // Need persist and prune diff layer
- if bc.db.DiffStore() != nil {
- bc.wg.Add(1)
- go bc.trustedDiffLayerLoop()
- }
-
if bc.doubleSignMonitor != nil {
bc.wg.Add(1)
go bc.startDoubleSignMonitor()
@@ -648,37 +625,6 @@ func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts, b
bc.receiptsCache.Add(hash, receipts)
}
-func (bc *BlockChain) cacheDiffLayer(diffLayer *types.DiffLayer, diffLayerCh chan struct{}) {
- // The difflayer in the system is stored by the map structure,
- // so it will be out of order.
- // It must be sorted first and then cached,
- // otherwise the DiffHash calculated by different nodes will be inconsistent
- sort.SliceStable(diffLayer.Codes, func(i, j int) bool {
- return diffLayer.Codes[i].Hash.Hex() < diffLayer.Codes[j].Hash.Hex()
- })
- sort.SliceStable(diffLayer.Destructs, func(i, j int) bool {
- return diffLayer.Destructs[i].Hex() < (diffLayer.Destructs[j].Hex())
- })
- sort.SliceStable(diffLayer.Accounts, func(i, j int) bool {
- return diffLayer.Accounts[i].Account.Hex() < diffLayer.Accounts[j].Account.Hex()
- })
- sort.SliceStable(diffLayer.Storages, func(i, j int) bool {
- return diffLayer.Storages[i].Account.Hex() < diffLayer.Storages[j].Account.Hex()
- })
- for index := range diffLayer.Storages {
- // Sort keys and vals by key.
- sort.Sort(&diffLayer.Storages[index])
- }
-
- bc.diffLayerCache.Add(diffLayer.BlockHash, diffLayer)
- close(diffLayerCh)
-
- if bc.db.DiffStore() != nil {
- // push to priority queue before persisting
- bc.diffQueueBuffer <- diffLayer
- }
-}
-
// empty returns an indicator whether the blockchain is empty.
// Note, it's a special case that we connect a non-empty ancient
// database with an empty node, so that we can plugin the ancient
@@ -1815,24 +1761,11 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
}()
// Commit all cached state changes into underlying memory database.
- root, diffLayer, err := statedb.Commit(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()), bc.chainConfig.IsCancun(block.Number(), block.Time()))
+ root, err := statedb.Commit(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()), bc.chainConfig.IsCancun(block.Number(), block.Time()))
if err != nil {
return err
}
- // Ensure no empty block body
- if diffLayer != nil && block.Header().TxHash != types.EmptyRootHash {
- // Filling necessary field
- diffLayer.Receipts = receipts
- diffLayer.BlockHash = block.Hash()
- diffLayer.Number = block.NumberU64()
-
- diffLayerCh := make(chan struct{})
- bc.diffLayerChanCache.Add(diffLayer.BlockHash, diffLayerCh)
-
- go bc.cacheDiffLayer(diffLayer, diffLayerCh)
- }
-
// If node is running in path mode, skip explicit gc operation
// which is unnecessary in this mode.
if bc.triedb.Scheme() == rawdb.PathScheme {
@@ -2980,81 +2913,6 @@ func (bc *BlockChain) updateFutureBlocks() {
}
}
-func (bc *BlockChain) trustedDiffLayerLoop() {
- recheck := time.NewTicker(diffLayerFreezerRecheckInterval)
- defer func() {
- recheck.Stop()
- bc.wg.Done()
- }()
- for {
- select {
- case diff := <-bc.diffQueueBuffer:
- bc.diffQueue.Push(diff, -(int64(diff.Number)))
- case <-bc.quit:
- // Persist all diffLayers when shutdown, it will introduce redundant storage, but it is acceptable.
- // If the client been ungracefully shutdown, it will missing all cached diff layers, it is acceptable as well.
- var batch ethdb.Batch
- for !bc.diffQueue.Empty() {
- diffLayer, _ := bc.diffQueue.Pop()
- if batch == nil {
- batch = bc.db.DiffStore().NewBatch()
- }
- rawdb.WriteDiffLayer(batch, diffLayer.BlockHash, diffLayer)
- if batch.ValueSize() > ethdb.IdealBatchSize {
- if err := batch.Write(); err != nil {
- log.Error("Failed to write diff layer", "err", err)
- return
- }
- batch.Reset()
- }
- }
- if batch != nil {
- // flush data
- if err := batch.Write(); err != nil {
- log.Error("Failed to write diff layer", "err", err)
- return
- }
- batch.Reset()
- }
- return
- case <-recheck.C:
- currentHeight := bc.CurrentBlock().Number.Uint64()
- var batch ethdb.Batch
- for !bc.diffQueue.Empty() {
- diffLayer, prio := bc.diffQueue.Pop()
-
- // if the block not old enough
- if int64(currentHeight)+prio < int64(bc.triesInMemory) {
- bc.diffQueue.Push(diffLayer, prio)
- break
- }
- canonicalHash := bc.GetCanonicalHash(uint64(-prio))
- // on the canonical chain
- if canonicalHash == diffLayer.BlockHash {
- if batch == nil {
- batch = bc.db.DiffStore().NewBatch()
- }
- rawdb.WriteDiffLayer(batch, diffLayer.BlockHash, diffLayer)
- staleHash := bc.GetCanonicalHash(uint64(-prio) - bc.diffLayerFreezerBlockLimit)
- rawdb.DeleteDiffLayer(batch, staleHash)
- }
- if batch != nil && batch.ValueSize() > ethdb.IdealBatchSize {
- if err := batch.Write(); err != nil {
- panic(fmt.Sprintf("Failed to write diff layer, error %v", err))
- }
- batch.Reset()
- }
- }
- if batch != nil {
- if err := batch.Write(); err != nil {
- panic(fmt.Sprintf("Failed to write diff layer, error %v", err))
- }
- batch.Reset()
- }
- }
- }
-}
-
func (bc *BlockChain) startDoubleSignMonitor() {
eventChan := make(chan ChainHeadEvent, monitor.MaxCacheHeader)
sub := bc.SubscribeChainHeadEvent(eventChan)
@@ -3186,137 +3044,11 @@ func (bc *BlockChain) HeadChain() *HeaderChain {
func (bc *BlockChain) TriesInMemory() uint64 { return bc.triesInMemory }
-func EnablePersistDiff(limit uint64) BlockChainOption {
- return func(chain *BlockChain) (*BlockChain, error) {
- chain.diffLayerFreezerBlockLimit = limit
- return chain, nil
- }
-}
-
-func EnableBlockValidator(chainConfig *params.ChainConfig, mode VerifyMode, peers verifyPeers) BlockChainOption {
- return func(bc *BlockChain) (*BlockChain, error) {
- if mode.NeedRemoteVerify() {
- vm, err := NewVerifyManager(bc, peers, mode == InsecureVerify)
- if err != nil {
- return nil, err
- }
- go vm.mainLoop()
- bc.validator = NewBlockValidator(chainConfig, bc, EnableRemoteVerifyManager(vm))
- }
- return bc, nil
- }
-}
-
func EnableDoubleSignChecker(bc *BlockChain) (*BlockChain, error) {
bc.doubleSignMonitor = monitor.NewDoubleSignMonitor()
return bc, nil
}
-func (bc *BlockChain) GetVerifyResult(blockNumber uint64, blockHash common.Hash, diffHash common.Hash) *VerifyResult {
- var res VerifyResult
- res.BlockNumber = blockNumber
- res.BlockHash = blockHash
-
- if blockNumber > bc.CurrentHeader().Number.Uint64()+maxDiffForkDist {
- res.Status = types.StatusBlockTooNew
- return &res
- } else if blockNumber > bc.CurrentHeader().Number.Uint64() {
- res.Status = types.StatusBlockNewer
- return &res
- }
-
- header := bc.GetHeaderByHash(blockHash)
- if header == nil {
- if blockNumber > bc.CurrentHeader().Number.Uint64()-maxDiffForkDist {
- res.Status = types.StatusPossibleFork
- return &res
- }
-
- res.Status = types.StatusImpossibleFork
- return &res
- }
-
- diff := bc.GetTrustedDiffLayer(blockHash)
- if diff != nil {
- if diff.DiffHash.Load() == nil {
- hash, err := CalculateDiffHash(diff)
- if err != nil {
- res.Status = types.StatusUnexpectedError
- return &res
- }
-
- diff.DiffHash.Store(hash)
- }
-
- if diffHash != diff.DiffHash.Load().(common.Hash) {
- res.Status = types.StatusDiffHashMismatch
- return &res
- }
-
- res.Status = types.StatusFullVerified
- res.Root = header.Root
- return &res
- }
-
- res.Status = types.StatusPartiallyVerified
- res.Root = header.Root
- return &res
-}
-
-func (bc *BlockChain) GetTrustedDiffLayer(blockHash common.Hash) *types.DiffLayer {
- if cached, ok := bc.diffLayerCache.Get(blockHash); ok {
- return cached
- }
-
- var diff *types.DiffLayer
- diffStore := bc.db.DiffStore()
- if diffStore != nil {
- diff = rawdb.ReadDiffLayer(diffStore, blockHash)
- }
- return diff
-}
-
-func CalculateDiffHash(d *types.DiffLayer) (common.Hash, error) {
- if d == nil {
- return common.Hash{}, errors.New("nil diff layer")
- }
-
- diff := &types.ExtDiffLayer{
- BlockHash: d.BlockHash,
- Receipts: make([]*types.ReceiptForStorage, 0),
- Number: d.Number,
- Codes: d.Codes,
- Destructs: d.Destructs,
- Accounts: d.Accounts,
- Storages: d.Storages,
- }
-
- for index, account := range diff.Accounts {
- full, err := types.FullAccount(account.Blob)
- if err != nil {
- return common.Hash{}, fmt.Errorf("decode full account error: %v", err)
- }
- // set account root to empty root
- full.Root = types.EmptyRootHash
- diff.Accounts[index].Blob = types.SlimAccountRLP(*full)
- }
-
- rawData, err := rlp.EncodeToBytes(diff)
- if err != nil {
- return common.Hash{}, fmt.Errorf("encode new diff error: %v", err)
- }
-
- hasher := sha3.NewLegacyKeccak256()
- _, err = hasher.Write(rawData)
- if err != nil {
- return common.Hash{}, fmt.Errorf("hasher write error: %v", err)
- }
-
- var hash common.Hash
- hasher.Sum(hash[:0])
- return hash, nil
-}
-
// SetBlockValidatorAndProcessorForTesting sets the current validator and processor.
// This method can be used to force an invalid blockchain to be verified for tests.
// This method is unsafe and should only be used before block import starts.
diff --git a/core/blockchain_diff_test.go b/core/blockchain_diff_test.go
deleted file mode 100644
index d6cbfa750c..0000000000
--- a/core/blockchain_diff_test.go
+++ /dev/null
@@ -1,428 +0,0 @@
-// Copyright 2020 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 .
-
-// Tests that abnormal program termination (i.e.crash) and restart doesn't leave
-// the database in some strange state with gaps in the chain, nor with block data
-// dangling in the future.
-
-package core
-
-import (
- "encoding/hex"
- "math/big"
- "testing"
- "time"
-
- "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/core/vm"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/ethdb/memorydb"
- "github.com/ethereum/go-ethereum/params"
-)
-
-var (
- // testKey is a private key to use for funding a tester account.
- testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
- contractCode, _ = hex.DecodeString("608060405260016000806101000a81548160ff02191690831515021790555034801561002a57600080fd5b506101688061003a6000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806389a2d8011461003b578063b0483f4814610059575b600080fd5b610043610075565b60405161005091906100f4565b60405180910390f35b610073600480360381019061006e91906100bc565b61008b565b005b60008060009054906101000a900460ff16905090565b806000806101000a81548160ff02191690831515021790555050565b6000813590506100b68161011b565b92915050565b6000602082840312156100ce57600080fd5b60006100dc848285016100a7565b91505092915050565b6100ee8161010f565b82525050565b600060208201905061010960008301846100e5565b92915050565b60008115159050919050565b6101248161010f565b811461012f57600080fd5b5056fea264697066735822122092f788b569bfc3786e90601b5dbec01cfc3d76094164fd66ca7d599c4239fc5164736f6c63430008000033")
- contractAddr = common.HexToAddress("0xe74a3c7427cda785e0000d42a705b1f3fd371e09")
- contractData1, _ = hex.DecodeString("b0483f480000000000000000000000000000000000000000000000000000000000000000")
- contractData2, _ = hex.DecodeString("b0483f480000000000000000000000000000000000000000000000000000000000000001")
- commonGas = 192138
- // testAddr is the Ethereum address of the tester account.
- testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
-
- // testBlocks is the test parameters array for specific blocks.
- testBlocks = []testBlockParam{
- {
- // This txs params also used to default block.
- blockNr: 11,
- txs: []testTransactionParam{
- {
- to: &common.Address{0x01},
- value: big.NewInt(1),
- gasPrice: big.NewInt(params.InitialBaseFee),
- data: nil,
- },
- },
- },
- {
- blockNr: 12,
- txs: []testTransactionParam{
- {
- to: &common.Address{0x01},
- value: big.NewInt(1),
- gasPrice: big.NewInt(params.InitialBaseFee),
- data: nil,
- },
- {
- to: &common.Address{0x02},
- value: big.NewInt(2),
- gasPrice: big.NewInt(params.InitialBaseFee + 1),
- data: nil,
- },
- {
- to: nil,
- value: big.NewInt(0),
- gasPrice: big.NewInt(params.InitialBaseFee + 1),
- data: contractCode,
- },
- },
- },
- {
- blockNr: 13,
- txs: []testTransactionParam{
- {
- to: &common.Address{0x01},
- value: big.NewInt(1),
- gasPrice: big.NewInt(params.InitialBaseFee),
- data: nil,
- },
- {
- to: &common.Address{0x02},
- value: big.NewInt(2),
- gasPrice: big.NewInt(params.InitialBaseFee + 1),
- data: nil,
- },
- {
- to: &common.Address{0x03},
- value: big.NewInt(3),
- gasPrice: big.NewInt(params.InitialBaseFee + 2),
- data: nil,
- },
- {
- to: &contractAddr,
- value: big.NewInt(0),
- gasPrice: big.NewInt(params.InitialBaseFee + 2),
- data: contractData1,
- },
- },
- },
- {
- blockNr: 14,
- txs: []testTransactionParam{
- {
- to: &contractAddr,
- value: big.NewInt(0),
- gasPrice: big.NewInt(params.InitialBaseFee + 2),
- data: contractData2,
- },
- },
- },
- {
- blockNr: 15,
- txs: []testTransactionParam{},
- },
- }
-)
-
-type testTransactionParam struct {
- to *common.Address
- value *big.Int
- gasPrice *big.Int
- data []byte
-}
-
-type testBlockParam struct {
- blockNr int
- txs []testTransactionParam
-}
-
-// 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.
-type testBackend struct {
- db ethdb.Database
- chain *BlockChain
-}
-
-// newTestBackend creates an empty chain and wraps it into a mock backend.
-func newTestBackend(blocks int, light bool) *testBackend {
- return newTestBackendWithGenerator(blocks, light)
-}
-
-// newTestBackendWithGenerator creates a chain with a number of explicitly defined blocks and
-// wraps it into a mock backend.
-func newTestBackendWithGenerator(blocks int, lightProcess bool) *testBackend {
- signer := types.HomesteadSigner{}
- // Create a database pre-initialize with a genesis block
- db := rawdb.NewMemoryDatabase()
- db.SetDiffStore(memorydb.New())
- gspec := &Genesis{
- Config: params.TestChainConfig,
- Alloc: GenesisAlloc{testAddr: {Balance: big.NewInt(100000000000000000)}},
- BaseFee: big.NewInt(params.InitialBaseFee),
- }
- chain, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, EnablePersistDiff(860000))
- generator := func(i int, block *BlockGen) {
- // The chain maker doesn't have access to a chain, so the difficulty will be
- // lets unset (nil). Set it here to the correct value.
- block.SetCoinbase(testAddr)
-
- for idx, testBlock := range testBlocks {
- // Specific block setting, the index in this generator has 1 diff from specified blockNr.
- if i+1 == testBlock.blockNr {
- for _, testTransaction := range testBlock.txs {
- var transaction *types.Transaction
- if testTransaction.to == nil {
- transaction = types.NewContractCreation(block.TxNonce(testAddr),
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data)
- } else {
- transaction = types.NewTransaction(block.TxNonce(testAddr), *testTransaction.to,
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data)
- }
- tx, err := types.SignTx(transaction, signer, testKey)
- if err != nil {
- panic(err)
- }
- block.AddTxWithChain(chain, tx)
- }
- break
- }
-
- // Default block setting.
- if idx == len(testBlocks)-1 {
- // We want to simulate an empty middle block, having the same state as the
- // first one. The last is needs a state change again to force a reorg.
- for _, testTransaction := range testBlocks[0].txs {
- tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddr), *testTransaction.to,
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data), signer, testKey)
- if err != nil {
- panic(err)
- }
- block.AddTxWithChain(chain, tx)
- }
- }
- }
- }
- bs, _ := GenerateChain(params.TestChainConfig, chain.Genesis(), ethash.NewFaker(), db, blocks, generator)
- if _, err := chain.InsertChain(bs); err != nil {
- panic(err)
- }
-
- return &testBackend{
- db: db,
- chain: chain,
- }
-}
-
-// close tears down the transaction pool and chain behind the mock backend.
-func (b *testBackend) close() {
- b.chain.Stop()
-}
-
-func (b *testBackend) Chain() *BlockChain { return b.chain }
-
-func TestFreezeDiffLayer(t *testing.T) {
- blockNum := 1024
- fullBackend := newTestBackend(blockNum, true)
- defer fullBackend.close()
- for len(fullBackend.chain.diffQueueBuffer) > 0 {
- // Wait for the buffer to be zero.
- }
- // Minus one empty block.
- if fullBackend.chain.diffQueue.Size() != blockNum-1 {
- t.Errorf("size of diff queue is wrong, expected: %d, get: %d", blockNum-1, fullBackend.chain.diffQueue.Size())
- }
-
- time.Sleep(diffLayerFreezerRecheckInterval + 2*time.Second)
- if fullBackend.chain.diffQueue.Size() != int(fullBackend.chain.triesInMemory) {
- t.Errorf("size of diff queue is wrong, expected: %d, get: %d", blockNum, fullBackend.chain.diffQueue.Size())
- }
-
- block := fullBackend.chain.GetBlockByNumber(uint64(blockNum / 2))
- diffStore := fullBackend.chain.db.DiffStore()
- rawData := rawdb.ReadDiffLayerRLP(diffStore, block.Hash())
- if len(rawData) == 0 {
- t.Error("do not find diff layer in db")
- }
-}
-
-// newTwoForkedBlockchains returns two blockchains, these two chains are generated by different
-// generators, they have some same parent blocks, the number of same blocks are determined by
-// testBlocks, once chain1 inserted a non-default block, chain1 and chain2 get forked.
-func newTwoForkedBlockchains(len1, len2 int) (chain1 *BlockChain, chain2 *BlockChain) {
- signer := types.HomesteadSigner{}
- // Create a database pre-initialize with a genesis block
- db1 := rawdb.NewMemoryDatabase()
- db1.SetDiffStore(memorydb.New())
- gspec := &Genesis{
- Config: params.TestChainConfig,
- Alloc: GenesisAlloc{testAddr: {Balance: big.NewInt(100000000000000000)}},
- BaseFee: big.NewInt(params.InitialBaseFee),
- }
- engine1 := ethash.NewFaker()
- chain1, _ = NewBlockChain(db1, nil, gspec, nil, engine1, vm.Config{}, nil, nil, EnablePersistDiff(860000), EnableBlockValidator(params.TestChainConfig, 0, nil))
- generator1 := func(i int, block *BlockGen) {
- // The chain maker doesn't have access to a chain, so the difficulty will be
- // lets unset (nil). Set it here to the correct value.
- block.SetCoinbase(testAddr)
-
- for idx, testBlock := range testBlocks {
- // Specific block setting, the index in this generator has 1 diff from specified blockNr.
- if i+1 == testBlock.blockNr {
- for _, testTransaction := range testBlock.txs {
- var transaction *types.Transaction
- if testTransaction.to == nil {
- transaction = types.NewContractCreation(block.TxNonce(testAddr),
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data)
- } else {
- transaction = types.NewTransaction(block.TxNonce(testAddr), *testTransaction.to,
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data)
- }
- tx, err := types.SignTx(transaction, signer, testKey)
- if err != nil {
- panic(err)
- }
- block.AddTxWithChain(chain1, tx)
- }
- break
- }
-
- // Default block setting.
- if idx == len(testBlocks)-1 {
- // We want to simulate an empty middle block, having the same state as the
- // first one. The last is needs a state change again to force a reorg.
- for _, testTransaction := range testBlocks[0].txs {
- tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddr), *testTransaction.to,
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data), signer, testKey)
- if err != nil {
- panic(err)
- }
- block.AddTxWithChain(chain1, tx)
- }
- }
- }
- }
- bs1, _ := GenerateChain(params.TestChainConfig, chain1.Genesis(), ethash.NewFaker(), db1, len1, generator1)
- if _, err := chain1.InsertChain(bs1); err != nil {
- panic(err)
- }
- waitDifflayerCached(chain1, bs1)
-
- // Create a database pre-initialize with a genesis block
- db2 := rawdb.NewMemoryDatabase()
- db2.SetDiffStore(memorydb.New())
- gspec2 := &Genesis{
- Config: params.TestChainConfig,
- Alloc: GenesisAlloc{testAddr: {Balance: big.NewInt(100000000000000000)}},
- BaseFee: big.NewInt(params.InitialBaseFee),
- }
- chain2, _ = NewBlockChain(db2, nil, gspec2, nil, ethash.NewFaker(), vm.Config{}, nil, nil, EnablePersistDiff(860000), EnableBlockValidator(params.TestChainConfig, 0, nil))
- generator2 := func(i int, block *BlockGen) {
- // The chain maker doesn't have access to a chain, so the difficulty will be
- // lets unset (nil). Set it here to the correct value.
- block.SetCoinbase(testAddr)
- // We want to simulate an empty middle block, having the same state as the
- // first one. The last is needs a state change again to force a reorg.
- for _, testTransaction := range testBlocks[0].txs {
- tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddr), *testTransaction.to,
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data), signer, testKey)
- if err != nil {
- panic(err)
- }
- block.AddTxWithChain(chain1, tx)
- }
- }
- bs2, _ := GenerateChain(params.TestChainConfig, chain2.Genesis(), ethash.NewFaker(), db2, len2, generator2)
- if _, err := chain2.InsertChain(bs2); err != nil {
- panic(err)
- }
- waitDifflayerCached(chain2, bs2)
-
- return chain1, chain2
-}
-
-func waitDifflayerCached(chain *BlockChain, bs types.Blocks) {
- for _, block := range bs {
- // wait for all difflayers to be cached
- for block.Header().TxHash != types.EmptyRootHash &&
- chain.GetTrustedDiffLayer(block.Hash()) == nil {
- time.Sleep(time.Second)
- }
- }
-}
-
-func testGetRootByDiffHash(t *testing.T, chain1, chain2 *BlockChain, blockNumber uint64, status types.VerifyStatus) {
- block2 := chain2.GetBlockByNumber(blockNumber)
- if block2 == nil {
- t.Fatalf("failed to find block, number: %v", blockNumber)
- }
- expect := VerifyResult{
- Status: status,
- BlockNumber: blockNumber,
- BlockHash: block2.Hash(),
- }
- if status.Code&0xff00 == types.StatusVerified.Code {
- expect.Root = block2.Root()
- }
-
- diffLayer2 := chain2.GetTrustedDiffLayer(block2.Hash())
- if diffLayer2 == nil {
- t.Fatal("failed to find diff layer")
- }
- diffHash2 := types.EmptyRootHash
- if status != types.StatusDiffHashMismatch {
- var err error
- diffHash2, err = CalculateDiffHash(diffLayer2)
- if err != nil {
- t.Fatalf("failed to compute diff hash: %v", err)
- }
- }
-
- if status == types.StatusPartiallyVerified {
- block1 := chain1.GetBlockByNumber(blockNumber)
- if block1 == nil {
- t.Fatalf("failed to find block, number: %v", blockNumber)
- }
- chain1.diffLayerCache.Remove(block1.Hash())
- }
-
- result := chain1.GetVerifyResult(blockNumber, block2.Hash(), diffHash2)
- if result.Status != expect.Status {
- t.Fatalf("failed to verify block, number: %v, expect status: %v, real status: %v", blockNumber, expect.Status, result.Status)
- }
- if result.Root != expect.Root {
- t.Fatalf("failed to verify block, number: %v, expect root: %v, real root: %v", blockNumber, expect.Root, result.Root)
- }
-}
-
-func TestGetRootByDiffHash(t *testing.T) {
- len1 := 23 // length of blockchain1
- len2 := 35 // length of blockchain2
- plen := 11 // length of same parent blocks, which determined by testBlocks.
-
- chain1, chain2 := newTwoForkedBlockchains(len1, len2)
- defer chain1.Stop()
- defer chain2.Stop()
-
- hash1 := chain1.GetBlockByNumber(uint64(plen)).Hash()
- hash2 := chain2.GetBlockByNumber(uint64(plen)).Hash()
- if hash1 != hash2 {
- t.Errorf("chain content mismatch at %d: have hash %v, want hash %v", plen, hash2, hash1)
- }
-
- testGetRootByDiffHash(t, chain1, chain2, 10, types.StatusFullVerified)
- testGetRootByDiffHash(t, chain1, chain2, 2, types.StatusPartiallyVerified)
- testGetRootByDiffHash(t, chain1, chain2, 10, types.StatusDiffHashMismatch)
- testGetRootByDiffHash(t, chain1, chain2, 12, types.StatusImpossibleFork)
- testGetRootByDiffHash(t, chain1, chain2, 20, types.StatusPossibleFork)
- testGetRootByDiffHash(t, chain1, chain2, 24, types.StatusBlockNewer)
- testGetRootByDiffHash(t, chain1, chain2, 35, types.StatusBlockTooNew)
-}
diff --git a/core/blockchain_notries_test.go b/core/blockchain_notries_test.go
deleted file mode 100644
index a2c84748aa..0000000000
--- a/core/blockchain_notries_test.go
+++ /dev/null
@@ -1,226 +0,0 @@
-// Copyright 2020 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 .
-
-// Tests that abnormal program termination (i.e.crash) and restart doesn't leave
-// the database in some strange state with gaps in the chain, nor with block data
-// dangling in the future.
-
-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/core/vm"
- "github.com/ethereum/go-ethereum/ethdb/memorydb"
- "github.com/ethereum/go-ethereum/params"
-)
-
-func newMockVerifyPeer() *mockVerifyPeer {
- return &mockVerifyPeer{}
-}
-
-type requestRoot struct {
- blockNumber uint64
- blockHash common.Hash
- diffHash common.Hash
-}
-
-type verifFailedStatus struct {
- status types.VerifyStatus
- blockNumber uint64
-}
-
-// mockVerifyPeer is a mocking struct that simulates p2p signals for verification tasks.
-type mockVerifyPeer struct {
- callback func(*requestRoot)
-}
-
-func (peer *mockVerifyPeer) setCallBack(callback func(*requestRoot)) {
- peer.callback = callback
-}
-
-func (peer *mockVerifyPeer) RequestRoot(blockNumber uint64, blockHash common.Hash, diffHash common.Hash) error {
- if peer.callback != nil {
- peer.callback(&requestRoot{blockNumber, blockHash, diffHash})
- }
- return nil
-}
-
-func (peer *mockVerifyPeer) ID() string {
- return "mock_peer"
-}
-
-type mockVerifyPeers struct {
- peers []VerifyPeer
-}
-
-func (peers *mockVerifyPeers) GetVerifyPeers() []VerifyPeer {
- return peers.peers
-}
-
-func newMockRemoteVerifyPeer(peers []VerifyPeer) *mockVerifyPeers {
- return &mockVerifyPeers{peers}
-}
-
-func makeTestBackendWithRemoteValidator(blocks int, mode VerifyMode, failed *verifFailedStatus) (*testBackend, *testBackend, []*types.Block, error) {
- signer := types.HomesteadSigner{}
-
- // Create a database pre-initialize with a genesis block
- db := rawdb.NewMemoryDatabase()
- db.SetDiffStore(memorydb.New())
- gspec := &Genesis{
- Config: params.TestChainConfig,
- Alloc: GenesisAlloc{testAddr: {Balance: big.NewInt(100000000000000000)}},
- }
- engine := ethash.NewFaker()
-
- db2 := rawdb.NewMemoryDatabase()
- db2.SetDiffStore(memorydb.New())
- gspec2 := &Genesis{
- Config: params.TestChainConfig,
- Alloc: GenesisAlloc{testAddr: {Balance: big.NewInt(100000000000000000)}},
- }
- engine2 := ethash.NewFaker()
-
- peer := newMockVerifyPeer()
- peers := []VerifyPeer{peer}
-
- verifier, err := NewBlockChain(db, nil, gspec, nil, engine, vm.Config{},
- nil, nil, EnablePersistDiff(100000), EnableBlockValidator(params.TestChainConfig, LocalVerify, nil))
- if err != nil {
- return nil, nil, nil, err
- }
-
- fastnode, err := NewBlockChain(db2, nil, gspec2, nil, engine2, vm.Config{},
- nil, nil, EnableBlockValidator(params.TestChainConfig, mode, newMockRemoteVerifyPeer(peers)))
- if err != nil {
- return nil, nil, nil, err
- }
-
- generator := func(i int, block *BlockGen) {
- // The chain maker doesn't have access to a chain, so the difficulty will be
- // lets unset (nil). Set it here to the correct value.
- block.SetCoinbase(testAddr)
-
- for idx, testBlock := range testBlocks {
- // Specific block setting, the index in this generator has 1 diff from specified blockNr.
- if i+1 == testBlock.blockNr {
- for _, testTransaction := range testBlock.txs {
- var transaction *types.Transaction
- if testTransaction.to == nil {
- transaction = types.NewContractCreation(block.TxNonce(testAddr),
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data)
- } else {
- transaction = types.NewTransaction(block.TxNonce(testAddr), *testTransaction.to,
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data)
- }
- tx, err := types.SignTx(transaction, signer, testKey)
- if err != nil {
- panic(err)
- }
- block.AddTxWithChain(verifier, tx)
- }
- break
- }
-
- // Default block setting.
- if idx == len(testBlocks)-1 {
- // We want to simulate an empty middle block, having the same state as the
- // first one. The last is needs a state change again to force a reorg.
- for _, testTransaction := range testBlocks[0].txs {
- tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddr), *testTransaction.to,
- testTransaction.value, uint64(commonGas), testTransaction.gasPrice, testTransaction.data), signer, testKey)
- if err != nil {
- panic(err)
- }
- block.AddTxWithChain(verifier, tx)
- }
- }
- }
- }
- peer.setCallBack(func(req *requestRoot) {
- if fastnode.validator != nil && fastnode.validator.RemoteVerifyManager() != nil {
- resp := verifier.GetVerifyResult(req.blockNumber, req.blockHash, req.diffHash)
- if failed != nil && req.blockNumber == failed.blockNumber {
- resp.Status = failed.status
- }
- fastnode.validator.RemoteVerifyManager().
- HandleRootResponse(
- resp, peer.ID())
- }
- })
-
- bs, _ := GenerateChain(params.TestChainConfig, verifier.Genesis(), ethash.NewFaker(), db, blocks, generator)
- if _, err := verifier.InsertChain(bs); err != nil {
- return nil, nil, nil, err
- }
- waitDifflayerCached(verifier, bs)
-
- return &testBackend{
- db: db,
- chain: verifier,
- },
- &testBackend{
- db: db2,
- chain: fastnode,
- }, bs, nil
-}
-
-func TestFastNode(t *testing.T) {
- // test full mode and succeed
- _, fastnode, blocks, err := makeTestBackendWithRemoteValidator(2048, FullVerify, nil)
- if err != nil {
- t.Fatalf("err: %v", err.Error())
- }
- _, err = fastnode.chain.InsertChain(blocks)
- if err != nil {
- t.Fatalf("err: %v", err.Error())
- }
- // test full mode and failed
- failed := &verifFailedStatus{status: types.StatusDiffHashMismatch, blockNumber: 204}
- _, fastnode, blocks, err = makeTestBackendWithRemoteValidator(2048, FullVerify, failed)
- if err != nil {
- t.Fatalf("err: %v", err.Error())
- }
- _, err = fastnode.chain.InsertChain(blocks)
- if err == nil || fastnode.chain.CurrentBlock().Number.Uint64() != failed.blockNumber+10 {
- t.Fatalf("blocks insert should be failed at height %d", failed.blockNumber+11)
- }
- // test insecure mode and succeed
- _, fastnode, blocks, err = makeTestBackendWithRemoteValidator(2048, InsecureVerify, nil)
- if err != nil {
- t.Fatalf("err: %v", err.Error())
- }
- _, err = fastnode.chain.InsertChain(blocks)
- if err != nil {
- t.Fatalf("err: %v", err.Error())
- }
- // test insecure mode and failed
- failed = &verifFailedStatus{status: types.StatusImpossibleFork, blockNumber: 204}
- _, fastnode, blocks, err = makeTestBackendWithRemoteValidator(2048, FullVerify, failed)
- if err != nil {
- t.Fatalf("err: %v", err.Error())
- }
- _, err = fastnode.chain.InsertChain(blocks)
- if err == nil || fastnode.chain.CurrentBlock().Number.Uint64() != failed.blockNumber+10 {
- t.Fatalf("blocks insert should be failed at height %d", failed.blockNumber+11)
- }
-}
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index d9fce1c75d..f5cd4f87c7 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -4226,6 +4226,10 @@ func (c *mockParlia) CalcDifficulty(chain consensus.ChainHeaderReader, time uint
}
func TestParliaBlobFeeReward(t *testing.T) {
+ testKey, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
+ // testAddr is the Ethereum address of the tester account.
+ testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
+
// Have N headers in the freezer
frdir := t.TempDir()
db, err := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), frdir, "", false, false, false, false, false)
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 1726057e51..57117c0d6a 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -445,7 +445,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
}
// Write state changes to db
- root, _, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number, b.header.Time))
+ root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number, b.header.Time))
if err != nil {
panic(fmt.Sprintf("state write error: %v", err))
}
@@ -548,7 +548,7 @@ func GenerateVerkleChain(config *params.ChainConfig, parent *types.Block, engine
}
// Write state changes to DB.
- root, _, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number, b.header.Time))
+ root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number, b.header.Time))
if err != nil {
panic(fmt.Sprintf("state write error: %v", err))
}
diff --git a/core/genesis.go b/core/genesis.go
index 4e3a26b507..21cab33803 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -159,7 +159,7 @@ func hashAlloc(ga *types.GenesisAlloc, isVerkle bool) (common.Hash, error) {
statedb.SetState(addr, key, value)
}
}
- root, _, err := statedb.Commit(0, false, false)
+ root, err := statedb.Commit(0, false, false)
return root, err
}
@@ -191,7 +191,7 @@ func flushAlloc(ga *types.GenesisAlloc, triedb *triedb.Database) (common.Hash, e
statedb.SetState(addr, key, value)
}
}
- root, _, err := statedb.Commit(0, false, false)
+ root, err := statedb.Commit(0, false, false)
if err != nil {
return common.Hash{}, err
}
diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go
index fc10d39420..759ebbe56b 100644
--- a/core/rawdb/accessors_chain.go
+++ b/core/rawdb/accessors_chain.go
@@ -531,44 +531,6 @@ func DeleteBody(db ethdb.KeyValueWriter, hash common.Hash, number uint64) {
}
}
-func WriteDiffLayer(db ethdb.KeyValueWriter, hash common.Hash, layer *types.DiffLayer) {
- data, err := rlp.EncodeToBytes(layer)
- if err != nil {
- log.Crit("Failed to RLP encode diff layer", "err", err)
- }
- WriteDiffLayerRLP(db, hash, data)
-}
-
-func WriteDiffLayerRLP(db ethdb.KeyValueWriter, blockHash common.Hash, rlp rlp.RawValue) {
- if err := db.Put(diffLayerKey(blockHash), rlp); err != nil {
- log.Crit("Failed to store diff layer", "err", err)
- }
-}
-
-func ReadDiffLayer(db ethdb.KeyValueReader, blockHash common.Hash) *types.DiffLayer {
- data := ReadDiffLayerRLP(db, blockHash)
- if len(data) == 0 {
- return nil
- }
- diff := new(types.DiffLayer)
- if err := rlp.Decode(bytes.NewReader(data), diff); err != nil {
- log.Error("Invalid diff layer RLP", "hash", blockHash, "err", err)
- return nil
- }
- return diff
-}
-
-func ReadDiffLayerRLP(db ethdb.KeyValueReader, blockHash common.Hash) rlp.RawValue {
- data, _ := db.Get(diffLayerKey(blockHash))
- return data
-}
-
-func DeleteDiffLayer(db ethdb.KeyValueWriter, blockHash common.Hash) {
- if err := db.Delete(diffLayerKey(blockHash)); err != nil {
- log.Crit("Failed to delete diffLayer", "err", err)
- }
-}
-
// ReadTdRLP retrieves a block's total difficulty corresponding to the hash in RLP encoding.
func ReadTdRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
var data []byte
diff --git a/core/rawdb/database.go b/core/rawdb/database.go
index e96863087f..9a4fe10cd6 100644
--- a/core/rawdb/database.go
+++ b/core/rawdb/database.go
@@ -41,7 +41,6 @@ type freezerdb struct {
ancientRoot string
ethdb.AncientFreezer
- diffStore ethdb.KeyValueStore
stateStore ethdb.Database
blockStore ethdb.Database
}
@@ -75,11 +74,6 @@ func (frdb *freezerdb) Close() error {
if err := frdb.KeyValueStore.Close(); err != nil {
errs = append(errs, err)
}
- if frdb.diffStore != nil {
- if err := frdb.diffStore.Close(); err != nil {
- errs = append(errs, err)
- }
- }
if frdb.stateStore != nil {
if err := frdb.stateStore.Close(); err != nil {
errs = append(errs, err)
@@ -96,17 +90,6 @@ func (frdb *freezerdb) Close() error {
return nil
}
-func (frdb *freezerdb) DiffStore() ethdb.KeyValueStore {
- return frdb.diffStore
-}
-
-func (frdb *freezerdb) SetDiffStore(diff ethdb.KeyValueStore) {
- if frdb.diffStore != nil {
- frdb.diffStore.Close()
- }
- frdb.diffStore = diff
-}
-
func (frdb *freezerdb) StateStore() ethdb.Database {
return frdb.stateStore
}
@@ -170,7 +153,6 @@ func (frdb *freezerdb) SetupFreezerEnv(env *ethdb.FreezerEnv) error {
// nofreezedb is a database wrapper that disables freezer data retrievals.
type nofreezedb struct {
ethdb.KeyValueStore
- diffStore ethdb.KeyValueStore
stateStore ethdb.Database
blockStore ethdb.Database
}
@@ -240,14 +222,6 @@ func (db *nofreezedb) SyncAncient() error {
return errNotSupported
}
-func (db *nofreezedb) DiffStore() ethdb.KeyValueStore {
- return db.diffStore
-}
-
-func (db *nofreezedb) SetDiffStore(diff ethdb.KeyValueStore) {
- db.diffStore = diff
-}
-
func (db *nofreezedb) StateStore() ethdb.Database {
return db.stateStore
}
@@ -396,16 +370,14 @@ func (db *emptyfreezedb) SyncAncient() error {
return nil
}
-func (db *emptyfreezedb) DiffStore() ethdb.KeyValueStore { return db }
-func (db *emptyfreezedb) SetDiffStore(diff ethdb.KeyValueStore) {}
-func (db *emptyfreezedb) StateStore() ethdb.Database { return db }
-func (db *emptyfreezedb) GetStateStore() ethdb.Database { return db }
-func (db *emptyfreezedb) SetStateStore(state ethdb.Database) {}
-func (db *emptyfreezedb) StateStoreReader() ethdb.Reader { return db }
-func (db *emptyfreezedb) BlockStore() ethdb.Database { return db }
-func (db *emptyfreezedb) SetBlockStore(block ethdb.Database) {}
-func (db *emptyfreezedb) HasSeparateBlockStore() bool { return false }
-func (db *emptyfreezedb) BlockStoreReader() ethdb.Reader { return db }
+func (db *emptyfreezedb) StateStore() ethdb.Database { return db }
+func (db *emptyfreezedb) GetStateStore() ethdb.Database { return db }
+func (db *emptyfreezedb) SetStateStore(state ethdb.Database) {}
+func (db *emptyfreezedb) StateStoreReader() ethdb.Reader { return db }
+func (db *emptyfreezedb) BlockStore() ethdb.Database { return db }
+func (db *emptyfreezedb) SetBlockStore(block ethdb.Database) {}
+func (db *emptyfreezedb) HasSeparateBlockStore() bool { return false }
+func (db *emptyfreezedb) BlockStoreReader() ethdb.Reader { return db }
func (db *emptyfreezedb) ReadAncients(fn func(reader ethdb.AncientReaderOp) error) (err error) {
return nil
}
diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go
index 36fdc9a4a3..58c3be45ba 100644
--- a/core/rawdb/schema.go
+++ b/core/rawdb/schema.go
@@ -126,9 +126,6 @@ var (
SnapshotStoragePrefix = []byte("o") // SnapshotStoragePrefix + account hash + storage hash -> storage trie value
CodePrefix = []byte("c") // CodePrefix + code hash -> account code
- // difflayer database
- diffLayerPrefix = []byte("d") // diffLayerPrefix + hash -> diffLayer
-
// Path-based storage scheme of merkle patricia trie.
TrieNodeAccountPrefix = []byte("A") // TrieNodeAccountPrefix + hexPath -> trie node
TrieNodeStoragePrefix = []byte("O") // TrieNodeStoragePrefix + accountHash + hexPath -> trie node
@@ -220,11 +217,6 @@ func blockBlobSidecarsKey(number uint64, hash common.Hash) []byte {
return append(append(BlockBlobSidecarsPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
}
-// diffLayerKey = diffLayerKeyPrefix + hash
-func diffLayerKey(hash common.Hash) []byte {
- return append(diffLayerPrefix, hash.Bytes()...)
-}
-
// txLookupKey = txLookupPrefix + hash
func txLookupKey(hash common.Hash) []byte {
return append(txLookupPrefix, hash.Bytes()...)
diff --git a/core/rawdb/table.go b/core/rawdb/table.go
index e924b043f3..54a6117de8 100644
--- a/core/rawdb/table.go
+++ b/core/rawdb/table.go
@@ -237,14 +237,6 @@ func (t *table) NewBatch() ethdb.Batch {
return &tableBatch{t.db.NewBatch(), t.prefix}
}
-func (t *table) DiffStore() ethdb.KeyValueStore {
- return nil
-}
-
-func (t *table) SetDiffStore(diff ethdb.KeyValueStore) {
- panic("not implement")
-}
-
func (t *table) StateStore() ethdb.Database {
return nil
}
diff --git a/core/remote_state_verifier.go b/core/remote_state_verifier.go
deleted file mode 100644
index 1a54423f83..0000000000
--- a/core/remote_state_verifier.go
+++ /dev/null
@@ -1,450 +0,0 @@
-package core
-
-import (
- "fmt"
- "math/big"
- "math/rand"
- "sync"
- "time"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/common/lru"
- "github.com/ethereum/go-ethereum/core/types"
- "github.com/ethereum/go-ethereum/event"
- "github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/metrics"
-)
-
-const (
- // chainHeadChanSize is the size of channel listening to ChainHeadEvent.
- chainHeadChanSize = 9
- verifiedCacheSize = 256
- maxForkHeight = 11
-
- // defaultPeerNumber is default number of verify peers
- defaultPeerNumber = 3
- // pruneHeightDiff indicates that if the height difference between current block and task's
- // corresponding block is larger than it, the task should be pruned.
- pruneHeightDiff = 15
- pruneInterval = 5 * time.Second
- resendInterval = 2 * time.Second
- // tryAllPeersTime is the time that a block has not been verified and then try all the valid verify peers.
- tryAllPeersTime = 15 * time.Second
- // maxWaitVerifyResultTime is the max time of waiting for ancestor's verify result.
- maxWaitVerifyResultTime = 30 * time.Second
-)
-
-var (
- verifyTaskCounter = metrics.NewRegisteredCounter("verifymanager/task/total", nil)
- verifyTaskSucceedMeter = metrics.NewRegisteredMeter("verifymanager/task/result/succeed", nil)
- verifyTaskFailedMeter = metrics.NewRegisteredMeter("verifymanager/task/result/failed", nil)
-
- verifyTaskExecutionTimer = metrics.NewRegisteredTimer("verifymanager/task/execution", nil)
-)
-
-type remoteVerifyManager struct {
- bc *BlockChain
- taskLock sync.RWMutex
- tasks map[common.Hash]*verifyTask
- peers verifyPeers
- verifiedCache *lru.Cache[common.Hash, bool]
- allowInsecure bool
-
- // Subscription
- chainBlockCh chan ChainHeadEvent
- chainHeadSub event.Subscription
-
- // Channels
- verifyCh chan common.Hash
- messageCh chan verifyMessage
-}
-
-func NewVerifyManager(blockchain *BlockChain, peers verifyPeers, allowInsecure bool) (*remoteVerifyManager, error) {
- verifiedCache := lru.NewCache[common.Hash, bool](verifiedCacheSize)
- block := blockchain.CurrentBlock()
- if block == nil {
- return nil, ErrCurrentBlockNotFound
- }
-
- // rewind to last non verified block
- number := new(big.Int).Sub(block.Number, big.NewInt(int64(maxForkHeight)))
- if number.Cmp(common.Big0) < 0 {
- blockchain.SetHead(0)
- } else {
- numberU64 := number.Uint64()
- blockchain.SetHead(numberU64)
- block := blockchain.GetBlockByNumber(numberU64)
- for i := 0; i < maxForkHeight && block.NumberU64() > 0; i++ {
- // When inserting a block,
- // the block before 11 blocks will be verified,
- // so the parent block of 11-22 will directly write the verification information.
- verifiedCache.Add(block.Hash(), true)
- block = blockchain.GetBlockByHash(block.ParentHash())
- if block == nil {
- return nil, fmt.Errorf("block is nil, number: %d", number)
- }
- }
- }
-
- vm := &remoteVerifyManager{
- bc: blockchain,
- tasks: make(map[common.Hash]*verifyTask),
- peers: peers,
- verifiedCache: verifiedCache,
- allowInsecure: allowInsecure,
-
- chainBlockCh: make(chan ChainHeadEvent, chainHeadChanSize),
- verifyCh: make(chan common.Hash, maxForkHeight),
- messageCh: make(chan verifyMessage),
- }
- vm.chainHeadSub = blockchain.SubscribeChainBlockEvent(vm.chainBlockCh)
- return vm, nil
-}
-
-func (vm *remoteVerifyManager) mainLoop() {
- defer vm.chainHeadSub.Unsubscribe()
-
- pruneTicker := time.NewTicker(pruneInterval)
- defer pruneTicker.Stop()
- for {
- select {
- case h := <-vm.chainBlockCh:
- vm.NewBlockVerifyTask(h.Header)
- case hash := <-vm.verifyCh:
- vm.cacheBlockVerified(hash)
- vm.taskLock.Lock()
- if task, ok := vm.tasks[hash]; ok {
- vm.CloseTask(task)
- verifyTaskSucceedMeter.Mark(1)
- verifyTaskExecutionTimer.Update(time.Since(task.startAt))
- }
- vm.taskLock.Unlock()
- case <-pruneTicker.C:
- vm.taskLock.Lock()
- for _, task := range vm.tasks {
- if vm.bc.insertStopped() || (vm.bc.CurrentHeader().Number.Cmp(task.blockHeader.Number) == 1 &&
- vm.bc.CurrentHeader().Number.Uint64()-task.blockHeader.Number.Uint64() > pruneHeightDiff) {
- vm.CloseTask(task)
- verifyTaskFailedMeter.Mark(1)
- }
- }
- vm.taskLock.Unlock()
- case message := <-vm.messageCh:
- vm.taskLock.RLock()
- if vt, ok := vm.tasks[message.verifyResult.BlockHash]; ok {
- vt.messageCh <- message
- }
- vm.taskLock.RUnlock()
- // System stopped
- case <-vm.bc.quit:
- vm.taskLock.RLock()
- for _, task := range vm.tasks {
- task.Close()
- }
- vm.taskLock.RUnlock()
- return
- case <-vm.chainHeadSub.Err():
- return
- }
- }
-}
-
-func (vm *remoteVerifyManager) NewBlockVerifyTask(header *types.Header) {
- for i := 0; header != nil && i <= maxForkHeight; i++ {
- // if is genesis block, mark it as verified and break.
- if header.Number.Uint64() == 0 {
- vm.cacheBlockVerified(header.Hash())
- break
- }
- func(hash common.Hash) {
- // if verified cache record that this block has been verified, skip.
- if _, ok := vm.verifiedCache.Get(hash); ok {
- return
- }
- // if there already has a verify task for this block, skip.
- vm.taskLock.RLock()
- _, ok := vm.tasks[hash]
- vm.taskLock.RUnlock()
- if ok {
- return
- }
-
- if header.TxHash == types.EmptyRootHash {
- log.Debug("this is an empty block:", "block", hash, "number", header.Number)
- vm.cacheBlockVerified(hash)
- return
- }
-
- var diffLayer *types.DiffLayer
- if cached, ok := vm.bc.diffLayerChanCache.Get(hash); ok {
- diffLayerCh := cached
- <-diffLayerCh
- diffLayer = vm.bc.GetTrustedDiffLayer(hash)
- }
- // if this block has no diff, there is no need to verify it.
- if diffLayer == nil {
- log.Info("block's trusted diffLayer is nil", "hash", hash, "number", header.Number)
- return
- }
- diffHash, err := CalculateDiffHash(diffLayer)
- if err != nil {
- log.Error("failed to get diff hash", "block", hash, "number", header.Number, "error", err)
- return
- }
- verifyTask := NewVerifyTask(diffHash, header, vm.peers, vm.verifyCh, vm.allowInsecure)
- vm.taskLock.Lock()
- vm.tasks[hash] = verifyTask
- vm.taskLock.Unlock()
- verifyTaskCounter.Inc(1)
- }(header.Hash())
- header = vm.bc.GetHeaderByHash(header.ParentHash)
- }
-}
-
-func (vm *remoteVerifyManager) cacheBlockVerified(hash common.Hash) {
- vm.verifiedCache.Add(hash, true)
-}
-
-// AncestorVerified function check block has been verified or it's a empty block.
-func (vm *remoteVerifyManager) AncestorVerified(header *types.Header) bool {
- // find header of H-11 block.
- header = vm.bc.GetHeaderByNumber(header.Number.Uint64() - maxForkHeight)
- // If start from genesis block, there has not a H-11 block,return true.
- // Either if the block is an empty block, return true.
- if header == nil || header.TxHash == types.EmptyRootHash {
- return true
- }
-
- hash := header.Hash()
-
- // Check if the task is complete
- vm.taskLock.RLock()
- task, exist := vm.tasks[hash]
- vm.taskLock.RUnlock()
- timeout := time.NewTimer(maxWaitVerifyResultTime)
- defer timeout.Stop()
- if exist {
- select {
- case <-task.terminalCh:
- case <-timeout.C:
- return false
- }
- }
-
- _, exist = vm.verifiedCache.Get(hash)
- return exist
-}
-
-func (vm *remoteVerifyManager) HandleRootResponse(vr *VerifyResult, pid string) error {
- vm.messageCh <- verifyMessage{verifyResult: vr, peerId: pid}
- return nil
-}
-
-func (vm *remoteVerifyManager) CloseTask(task *verifyTask) {
- delete(vm.tasks, task.blockHeader.Hash())
- task.Close()
- verifyTaskCounter.Dec(1)
-}
-
-type VerifyResult struct {
- Status types.VerifyStatus
- BlockNumber uint64
- BlockHash common.Hash
- Root common.Hash
-}
-
-type verifyMessage struct {
- verifyResult *VerifyResult
- peerId string
-}
-
-type verifyTask struct {
- diffhash common.Hash
- blockHeader *types.Header
- candidatePeers verifyPeers
- badPeers map[string]struct{}
- startAt time.Time
- allowInsecure bool
-
- messageCh chan verifyMessage
- terminalCh chan struct{}
-}
-
-func NewVerifyTask(diffhash common.Hash, header *types.Header, peers verifyPeers, verifyCh chan common.Hash, allowInsecure bool) *verifyTask {
- vt := &verifyTask{
- diffhash: diffhash,
- blockHeader: header,
- candidatePeers: peers,
- badPeers: make(map[string]struct{}),
- allowInsecure: allowInsecure,
- messageCh: make(chan verifyMessage),
- terminalCh: make(chan struct{}),
- }
- go vt.Start(verifyCh)
- return vt
-}
-
-func (vt *verifyTask) Close() {
- // It is safe to call close multiple
- select {
- case <-vt.terminalCh:
- default:
- close(vt.terminalCh)
- }
-}
-
-func (vt *verifyTask) Start(verifyCh chan common.Hash) {
- vt.startAt = time.Now()
-
- vt.sendVerifyRequest(defaultPeerNumber)
- resend := time.NewTicker(resendInterval)
- defer resend.Stop()
- for {
- select {
- case msg := <-vt.messageCh:
- switch msg.verifyResult.Status {
- case types.StatusFullVerified:
- vt.compareRootHashAndMark(msg, verifyCh)
- case types.StatusPartiallyVerified:
- log.Warn("block is insecure verified", "hash", msg.verifyResult.BlockHash, "number", msg.verifyResult.BlockNumber)
- if vt.allowInsecure {
- vt.compareRootHashAndMark(msg, verifyCh)
- }
- case types.StatusDiffHashMismatch, types.StatusImpossibleFork, types.StatusUnexpectedError:
- vt.badPeers[msg.peerId] = struct{}{}
- log.Info("peer is not available", "hash", msg.verifyResult.BlockHash, "number", msg.verifyResult.BlockNumber, "peer", msg.peerId, "reason", msg.verifyResult.Status.Msg)
- case types.StatusBlockTooNew, types.StatusBlockNewer, types.StatusPossibleFork:
- log.Info("return msg from peer", "peerId", msg.peerId, "hash", msg.verifyResult.BlockHash, "msg", msg.verifyResult.Status.Msg)
- }
- newVerifyMsgTypeGauge(msg.verifyResult.Status.Code, msg.peerId).Inc(1)
- case <-resend.C:
- // if a task has run over 15s, try all the valid peers to verify.
- if time.Since(vt.startAt) < tryAllPeersTime {
- vt.sendVerifyRequest(1)
- } else {
- vt.sendVerifyRequest(-1)
- }
- case <-vt.terminalCh:
- return
- }
- }
-}
-
-// sendVerifyRequest func select at most n peers from (candidatePeers-badPeers) randomly and send verify request.
-// when n<0, send to all the peers exclude badPeers.
-func (vt *verifyTask) sendVerifyRequest(n int) {
- var validPeers []VerifyPeer
- candidatePeers := vt.candidatePeers.GetVerifyPeers()
- for _, p := range candidatePeers {
- if _, ok := vt.badPeers[p.ID()]; !ok {
- validPeers = append(validPeers, p)
- }
- }
- // if has not valid peer, log warning.
- if len(validPeers) == 0 {
- log.Warn("there is no valid peer for block", "number", vt.blockHeader.Number)
- return
- }
-
- if n < len(validPeers) && n > 0 {
- // rand.Seed(time.Now().UnixNano())
- r := rand.New(rand.NewSource(time.Now().UnixNano()))
- r.Shuffle(len(validPeers), func(i, j int) { validPeers[i], validPeers[j] = validPeers[j], validPeers[i] })
- } else {
- n = len(validPeers)
- }
- for i := 0; i < n; i++ {
- p := validPeers[i]
- p.RequestRoot(vt.blockHeader.Number.Uint64(), vt.blockHeader.Hash(), vt.diffhash)
- }
-}
-
-func (vt *verifyTask) compareRootHashAndMark(msg verifyMessage, verifyCh chan common.Hash) {
- if msg.verifyResult.Root == vt.blockHeader.Root {
- // write back to manager so that manager can cache the result and delete this task.
- verifyCh <- msg.verifyResult.BlockHash
- } else {
- vt.badPeers[msg.peerId] = struct{}{}
- }
-}
-
-type VerifyPeer interface {
- RequestRoot(blockNumber uint64, blockHash common.Hash, diffHash common.Hash) error
- ID() string
-}
-
-type verifyPeers interface {
- GetVerifyPeers() []VerifyPeer
-}
-
-type VerifyMode uint32
-
-const (
- LocalVerify VerifyMode = iota
- FullVerify
- InsecureVerify
- NoneVerify
-)
-
-func (mode VerifyMode) IsValid() bool {
- return mode >= LocalVerify && mode <= NoneVerify
-}
-
-func (mode VerifyMode) String() string {
- switch mode {
- case LocalVerify:
- return "local"
- case FullVerify:
- return "full"
- case InsecureVerify:
- return "insecure"
- case NoneVerify:
- return "none"
- default:
- return "unknown"
- }
-}
-
-func (mode VerifyMode) MarshalText() ([]byte, error) {
- switch mode {
- case LocalVerify:
- return []byte("local"), nil
- case FullVerify:
- return []byte("full"), nil
- case InsecureVerify:
- return []byte("insecure"), nil
- case NoneVerify:
- return []byte("none"), nil
- default:
- return nil, fmt.Errorf("unknown verify mode %d", mode)
- }
-}
-
-func (mode *VerifyMode) UnmarshalText(text []byte) error {
- switch string(text) {
- case "local":
- *mode = LocalVerify
- case "full":
- *mode = FullVerify
- case "insecure":
- *mode = InsecureVerify
- case "none":
- *mode = NoneVerify
- default:
- return fmt.Errorf(`unknown sync mode %q, want "full", "light" or "insecure"`, text)
- }
- return nil
-}
-
-func (mode VerifyMode) NeedRemoteVerify() bool {
- return mode == FullVerify || mode == InsecureVerify
-}
-
-func (mode VerifyMode) NoTries() bool {
- return mode != LocalVerify
-}
-
-func newVerifyMsgTypeGauge(msgType uint16, peerId string) *metrics.Gauge {
- m := fmt.Sprintf("verifymanager/message/%d/peer/%s", msgType, peerId)
- return metrics.GetOrRegisterGauge(m, nil)
-}
diff --git a/core/state/pruner/pruner.go b/core/state/pruner/pruner.go
index 80a47d2dff..4bed620bd6 100644
--- a/core/state/pruner/pruner.go
+++ b/core/state/pruner/pruner.go
@@ -242,7 +242,7 @@ func (p *Pruner) pruneAll(maindb ethdb.Database, g *core.Genesis) error {
statedb.SetState(addr, key, value)
}
}
- root, _, _ := statedb.Commit(0, false, false)
+ root, _ := statedb.Commit(0, false, false)
statedb.Database().TrieDB().Commit(root, true)
log.Info("State pruning successful", "pruned", size, "elapsed", common.PrettyDuration(time.Since(start)))
return nil
diff --git a/core/state/state_test.go b/core/state/state_test.go
index 009b521143..b443411f1b 100644
--- a/core/state/state_test.go
+++ b/core/state/state_test.go
@@ -56,7 +56,7 @@ func TestDump(t *testing.T) {
// write some of them to the trie
s.state.updateStateObject(obj1)
s.state.updateStateObject(obj2)
- root, _, _ := s.state.Commit(0, false, false)
+ root, _ := s.state.Commit(0, false, false)
// check that DumpToCollector contains the state objects that are in trie
s.state, _ = New(root, tdb)
@@ -116,7 +116,7 @@ func TestIterativeDump(t *testing.T) {
// write some of them to the trie
s.state.updateStateObject(obj1)
s.state.updateStateObject(obj2)
- root, _, _ := s.state.Commit(0, false, false)
+ root, _ := s.state.Commit(0, false, false)
s.state, _ = New(root, tdb)
b := &bytes.Buffer{}
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 97fc8dcb1d..bb1599a650 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -1456,21 +1456,11 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool, noStorag
return nil, err
}
- snaps := s.db.Snapshot()
- if snaps != nil {
- ret.diffLayer = &types.DiffLayer{}
- }
// Commit dirty contract code if any exists
if db := s.db.TrieDB().Disk(); db != nil && len(ret.codes) > 0 {
batch := db.NewBatch()
for _, code := range ret.codes {
rawdb.WriteCode(batch, code.hash, code.blob)
- if snaps != nil {
- ret.diffLayer.Codes = append(ret.diffLayer.Codes, types.DiffCode{
- Hash: code.hash,
- Code: code.blob,
- })
- }
}
if err := batch.Write(); err != nil {
@@ -1524,12 +1514,12 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool, noStorag
// Since self-destruction was deprecated with the Cancun fork and there are
// no empty accounts left that could be deleted by EIP-158, storage wiping
// should not occur.
-func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool, noStorageWiping bool) (common.Hash, *types.DiffLayer, error) {
+func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool, noStorageWiping bool) (common.Hash, error) {
ret, err := s.commitAndFlush(block, deleteEmptyObjects, noStorageWiping)
if err != nil {
- return common.Hash{}, nil, err
+ return common.Hash{}, err
}
- return ret.root, ret.diffLayer, nil
+ return ret.root, nil
}
// Prepare handles the preparatory steps for executing a state transition with.
diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go
index 780b4d1441..65c2085a27 100644
--- a/core/state/statedb_test.go
+++ b/core/state/statedb_test.go
@@ -119,7 +119,7 @@ func TestIntermediateLeaks(t *testing.T) {
}
// Commit and cross check the databases.
- transRoot, _, err := transState.Commit(0, false, false)
+ transRoot, err := transState.Commit(0, false, false)
if err != nil {
t.Fatalf("failed to commit transition state: %v", err)
}
@@ -127,7 +127,7 @@ func TestIntermediateLeaks(t *testing.T) {
t.Errorf("can not commit trie %v to persistent database", transRoot.Hex())
}
- finalRoot, _, err := finalState.Commit(0, false, false)
+ finalRoot, err := finalState.Commit(0, false, false)
if err != nil {
t.Fatalf("failed to commit final state: %v", err)
}
@@ -240,7 +240,7 @@ func TestCopyWithDirtyJournal(t *testing.T) {
obj.data.Root = common.HexToHash("0xdeadbeef")
orig.updateStateObject(obj)
}
- root, _, _ := orig.Commit(0, true, false)
+ root, _ := orig.Commit(0, true, false)
orig, _ = New(root, db)
// modify all in memory without finalizing
@@ -696,7 +696,7 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
func TestTouchDelete(t *testing.T) {
s := newStateEnv()
s.state.getOrNewStateObject(common.Address{})
- root, _, _ := s.state.Commit(0, false, false)
+ root, _ := s.state.Commit(0, false, false)
s.state, _ = New(root, s.state.db)
snapshot := s.state.Snapshot()
@@ -784,7 +784,7 @@ func TestCopyCommitCopy(t *testing.T) {
t.Fatalf("second copy committed storage slot mismatch: have %x, want %x", val, sval)
}
// Commit state, ensure states can be loaded from disk
- root, _, _ := state.Commit(0, false, false)
+ root, _ := state.Commit(0, false, false)
state, _ = New(root, tdb)
if balance := state.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 {
t.Fatalf("state post-commit balance mismatch: have %v, want %v", balance, 42)
@@ -898,7 +898,7 @@ func TestCommitCopy(t *testing.T) {
if val := state.GetCommittedState(addr, skey1); val != (common.Hash{}) {
t.Fatalf("initial committed storage slot mismatch: have %x, want %x", val, common.Hash{})
}
- root, _, _ := state.Commit(0, true, false)
+ root, _ := state.Commit(0, true, false)
state, _ = New(root, db)
state.SetState(addr, skey2, sval2)
@@ -943,7 +943,7 @@ func TestDeleteCreateRevert(t *testing.T) {
addr := common.BytesToAddress([]byte("so"))
state.SetBalance(addr, uint256.NewInt(1), tracing.BalanceChangeUnspecified)
- root, _, _ := state.Commit(0, false, false)
+ root, _ := state.Commit(0, false, false)
state, _ = New(root, state.db)
// Simulate self-destructing in one transaction, then create-reverting in another
@@ -955,7 +955,7 @@ func TestDeleteCreateRevert(t *testing.T) {
state.RevertToSnapshot(id)
// Commit the entire state and make sure we don't crash and have the correct state
- root, _, _ = state.Commit(0, true, false)
+ root, _ = state.Commit(0, true, false)
state, _ = New(root, state.db)
if state.getStateObject(addr) != nil {
@@ -998,7 +998,7 @@ func testMissingTrieNodes(t *testing.T, scheme string) {
a2 := common.BytesToAddress([]byte("another"))
state.SetBalance(a2, uint256.NewInt(100), tracing.BalanceChangeUnspecified)
state.SetCode(a2, []byte{1, 2, 4})
- root, _, _ = state.Commit(0, false, false)
+ root, _ = state.Commit(0, false, false)
t.Logf("root: %x", root)
// force-flush
tdb.Commit(root, false)
@@ -1022,7 +1022,7 @@ func testMissingTrieNodes(t *testing.T, scheme string) {
}
// Modify the state
state.SetBalance(addr, uint256.NewInt(2), tracing.BalanceChangeUnspecified)
- root, _, err := state.Commit(0, false, false)
+ root, err := state.Commit(0, false, false)
if err == nil {
t.Fatalf("expected error, got root :%x", root)
}
@@ -1213,7 +1213,7 @@ func TestFlushOrderDataLoss(t *testing.T) {
state.SetState(common.Address{a}, common.Hash{a, s}, common.Hash{a, s})
}
}
- root, _, err := state.Commit(0, false, false)
+ root, err := state.Commit(0, false, false)
if err != nil {
t.Fatalf("failed to commit state trie: %v", err)
}
@@ -1288,7 +1288,7 @@ func TestDeleteStorage(t *testing.T) {
value := common.Hash(uint256.NewInt(uint64(10 * i)).Bytes32())
state.SetState(addr, slot, value)
}
- root, _, _ := state.Commit(0, true, false)
+ root, _ := state.Commit(0, true, false)
// Init phase done, create two states, one with snap and one without
fastState, _ := New(root, NewDatabase(tdb, snaps))
slowState, _ := New(root, NewDatabase(tdb, nil))
diff --git a/core/state/stateupdate.go b/core/state/stateupdate.go
index 246b45841b..e99f8ee1d2 100644
--- a/core/state/stateupdate.go
+++ b/core/state/stateupdate.go
@@ -20,7 +20,6 @@ import (
"maps"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie/trienode"
"github.com/ethereum/go-ethereum/triedb"
)
@@ -83,8 +82,6 @@ type stateUpdate struct {
codes map[common.Address]contractCode // codes contains the set of dirty codes
nodes *trienode.MergedNodeSet // Aggregated dirty nodes caused by state changes
-
- diffLayer *types.DiffLayer // snapshot diffLayer generated by current block
}
// empty returns a flag indicating the state transition is empty or not.
@@ -178,33 +175,6 @@ func newStateUpdate(rawStorageKey bool, originRoot common.Hash, root common.Hash
nodes: nodes,
}
- if sc.diffLayer != nil {
- for account := range destructsAddrs {
- sc.diffLayer.Destructs = append(sc.diffLayer.Destructs, account)
- }
-
- for accountHash, account := range sc.accounts {
- sc.diffLayer.Accounts = append(sc.diffLayer.Accounts, types.DiffAccount{
- Account: accountHash,
- Blob: account,
- })
- }
-
- for accountHash, storage := range sc.storages {
- keys := make([]common.Hash, 0, len(storage))
- values := make([][]byte, 0, len(storage))
- for k, v := range storage {
- keys = append(keys, k)
- values = append(values, v)
- }
- sc.diffLayer.Storages = append(sc.diffLayer.Storages, types.DiffStorage{
- Account: accountHash,
- Keys: keys,
- Vals: values,
- })
- }
- }
-
return sc
}
diff --git a/core/state/sync_test.go b/core/state/sync_test.go
index 698a6a2a43..2ed0658d8b 100644
--- a/core/state/sync_test.go
+++ b/core/state/sync_test.go
@@ -79,7 +79,7 @@ func makeTestState(scheme string) (ethdb.Database, Database, *triedb.Database, c
}
accounts = append(accounts, acc)
}
- root, _, _ := state.Commit(0, false, false)
+ root, _ := state.Commit(0, false, false)
// Return the generated state
return db, sdb, nodeDb, root, accounts
diff --git a/core/state/trie_prefetcher_test.go b/core/state/trie_prefetcher_test.go
index 9d6481b5ad..8d3cb1536f 100644
--- a/core/state/trie_prefetcher_test.go
+++ b/core/state/trie_prefetcher_test.go
@@ -145,7 +145,7 @@ func testVerklePrefetcher(t *testing.T) {
state.SetBalance(addr, uint256.NewInt(42), tracing.BalanceChangeUnspecified) // Change the account trie
state.SetCode(addr, []byte("hello")) // Change an external metadata
state.SetState(addr, skey, sval) // Change the storage trie
- root, _, _ := state.Commit(0, true, false)
+ root, _ := state.Commit(0, true, false)
state, _ = New(root, sdb)
sRoot := state.GetStorageRoot(addr)
diff --git a/core/types.go b/core/types.go
index d174e3f14b..756713a792 100644
--- a/core/types.go
+++ b/core/types.go
@@ -31,9 +31,6 @@ type Validator interface {
// ValidateState validates the given statedb and optionally the process result.
ValidateState(block *types.Block, state *state.StateDB, res *ProcessResult, stateless bool) error
-
- // RemoteVerifyManager return remoteVerifyManager of validator.
- RemoteVerifyManager() *remoteVerifyManager
}
type TransactionsByPriceAndNonce interface {
diff --git a/core/types/block.go b/core/types/block.go
index f359850a0a..cd082a831b 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -651,97 +651,6 @@ func HeaderParentHashFromRLP(header []byte) common.Hash {
return common.BytesToHash(parentHash)
}
-type DiffLayer struct {
- BlockHash common.Hash
- Number uint64
- Receipts Receipts // Receipts are duplicated stored to simplify the logic
- Codes []DiffCode
- Destructs []common.Address
- Accounts []DiffAccount
- Storages []DiffStorage
-
- DiffHash atomic.Value
-}
-
-type ExtDiffLayer struct {
- BlockHash common.Hash
- Number uint64
- Receipts []*ReceiptForStorage // Receipts are duplicated stored to simplify the logic
- Codes []DiffCode
- Destructs []common.Address
- Accounts []DiffAccount
- Storages []DiffStorage
-}
-
-// DecodeRLP decodes the Ethereum
-func (d *DiffLayer) DecodeRLP(s *rlp.Stream) error {
- var ed ExtDiffLayer
- if err := s.Decode(&ed); err != nil {
- return err
- }
- d.BlockHash, d.Number, d.Codes, d.Destructs, d.Accounts, d.Storages = ed.BlockHash, ed.Number, ed.Codes, ed.Destructs, ed.Accounts, ed.Storages
-
- d.Receipts = make([]*Receipt, len(ed.Receipts))
- for i, storageReceipt := range ed.Receipts {
- d.Receipts[i] = (*Receipt)(storageReceipt)
- }
- return nil
-}
-
-// EncodeRLP serializes b into the Ethereum RLP block format.
-func (d *DiffLayer) EncodeRLP(w io.Writer) error {
- storageReceipts := make([]*ReceiptForStorage, len(d.Receipts))
- for i, receipt := range d.Receipts {
- storageReceipts[i] = (*ReceiptForStorage)(receipt)
- }
- return rlp.Encode(w, ExtDiffLayer{
- BlockHash: d.BlockHash,
- Number: d.Number,
- Receipts: storageReceipts,
- Codes: d.Codes,
- Destructs: d.Destructs,
- Accounts: d.Accounts,
- Storages: d.Storages,
- })
-}
-
-type DiffCode struct {
- Hash common.Hash
- Code []byte
-}
-
-type DiffAccount struct {
- Account common.Hash
- Blob []byte
-}
-
-type DiffStorage struct {
- Account common.Hash
- Keys []common.Hash // Keys are hashed ones
- Vals [][]byte
-}
-
-func (storage *DiffStorage) Len() int { return len(storage.Keys) }
-func (storage *DiffStorage) Swap(i, j int) {
- storage.Keys[i], storage.Keys[j] = storage.Keys[j], storage.Keys[i]
- storage.Vals[i], storage.Vals[j] = storage.Vals[j], storage.Vals[i]
-}
-
-func (storage *DiffStorage) Less(i, j int) bool {
- return string(storage.Keys[i][:]) < string(storage.Keys[j][:])
-}
-
-type DiffAccountsInTx struct {
- TxHash common.Hash
- Accounts map[common.Address]*big.Int
-}
-
-type DiffAccountsInBlock struct {
- Number uint64
- BlockHash common.Hash
- Transactions []DiffAccountsInTx
-}
-
var extraSeal = 65 // Fixed number of extra-data suffix bytes reserved for signer seal
// SealHash returns the hash of a block prior to it being sealed.
diff --git a/core/verify_mode.go b/core/verify_mode.go
new file mode 100644
index 0000000000..20b29c6a21
--- /dev/null
+++ b/core/verify_mode.go
@@ -0,0 +1,54 @@
+package core
+
+import (
+ "fmt"
+)
+
+type VerifyMode uint32
+
+const (
+ LocalVerify VerifyMode = iota
+ NoneVerify
+)
+
+func (mode VerifyMode) IsValid() bool {
+ return mode >= LocalVerify && mode <= NoneVerify
+}
+
+func (mode VerifyMode) String() string {
+ switch mode {
+ case LocalVerify:
+ return "local"
+ case NoneVerify:
+ return "none"
+ default:
+ return "unknown"
+ }
+}
+
+func (mode VerifyMode) MarshalText() ([]byte, error) {
+ switch mode {
+ case LocalVerify:
+ return []byte("local"), nil
+ case NoneVerify:
+ return []byte("none"), nil
+ default:
+ return nil, fmt.Errorf("unknown verify mode %d", mode)
+ }
+}
+
+func (mode *VerifyMode) UnmarshalText(text []byte) error {
+ switch string(text) {
+ case "local":
+ *mode = LocalVerify
+ case "none":
+ *mode = NoneVerify
+ default:
+ return fmt.Errorf(`unknown sync mode %q, want "local" or "none"`, text)
+ }
+ return nil
+}
+
+func (mode VerifyMode) NoTries() bool {
+ return mode != LocalVerify
+}
diff --git a/eth/api_debug_test.go b/eth/api_debug_test.go
index 54dbf449b6..02b85f69fd 100644
--- a/eth/api_debug_test.go
+++ b/eth/api_debug_test.go
@@ -82,7 +82,7 @@ func TestAccountRange(t *testing.T) {
m[addr] = true
}
}
- root, _, _ := sdb.Commit(0, true, false)
+ root, _ := sdb.Commit(0, true, false)
sdb, _ = state.New(root, statedb)
trie, err := statedb.OpenTrie(root)
@@ -183,7 +183,7 @@ func TestStorageRangeAt(t *testing.T) {
for _, entry := range storage {
sdb.SetState(addr, *entry.Key, entry.Value)
}
- root, _, _ := sdb.Commit(0, false, false)
+ root, _ := sdb.Commit(0, false, false)
sdb, _ = state.New(root, db)
// Check a few combinations of limit and start/end.
diff --git a/eth/backend.go b/eth/backend.go
index f13999e88c..f1e504f06c 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -53,7 +53,6 @@ import (
"github.com/ethereum/go-ethereum/eth/protocols/bsc"
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
- "github.com/ethereum/go-ethereum/eth/protocols/trust"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
@@ -335,15 +334,11 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}
bcOps := make([]core.BlockChainOption, 0)
- if config.PersistDiff {
- bcOps = append(bcOps, core.EnablePersistDiff(config.DiffBlock))
- }
if stack.Config().EnableDoubleSignMonitor {
bcOps = append(bcOps, core.EnableDoubleSignChecker)
}
peers := newPeerSet()
- bcOps = append(bcOps, core.EnableBlockValidator(chainConfig, config.TriesVerifyMode, peers))
// TODO (MariusVanDerWijden) get rid of shouldPreserve in a follow-up PR
shouldPreserve := func(header *types.Header) bool {
return false
@@ -765,9 +760,6 @@ func (s *Ethereum) Protocols() []p2p.Protocol {
if !s.config.DisableSnapProtocol && s.config.SnapshotCache > 0 {
protos = append(protos, snap.MakeProtocols((*snapHandler)(s.handler))...)
}
- if s.config.EnableTrustProtocol {
- protos = append(protos, trust.MakeProtocols((*trustHandler)(s.handler))...)
- }
protos = append(protos, bsc.MakeProtocols((*bscHandler)(s.handler))...)
return protos
@@ -814,15 +806,6 @@ func (s *Ethereum) setupDiscovery() error {
s.discmix.AddSource(iter)
}
- // Add trust nodes from DNS.
- if len(s.config.TrustDiscoveryURLs) > 0 {
- iter, err := dnsclient.NewIterator(s.config.TrustDiscoveryURLs...)
- if err != nil {
- return err
- }
- s.discmix.AddSource(iter)
- }
-
// Add bsc nodes from DNS.
if len(s.config.BscDiscoveryURLs) > 0 {
iter, err := dnsclient.NewIterator(s.config.BscDiscoveryURLs...)
diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go
index 4f57dc68c4..bd66f2c593 100644
--- a/eth/ethconfig/config.go
+++ b/eth/ethconfig/config.go
@@ -62,7 +62,6 @@ var Defaults = Config{
TriesInMemory: 128,
TriesVerifyMode: core.LocalVerify,
SnapshotCache: 102,
- DiffBlock: uint64(86400),
FilterLogCacheSize: 32,
Miner: minerconfig.DefaultConfig,
TxPool: legacypool.DefaultConfig,
@@ -98,10 +97,9 @@ type Config struct {
EVNNodeIDsToRemove []enode.ID
// This can be set to list of enrtree:// URLs which will be queried for
// nodes to connect to.
- EthDiscoveryURLs []string
- SnapDiscoveryURLs []string
- TrustDiscoveryURLs []string
- BscDiscoveryURLs []string
+ EthDiscoveryURLs []string
+ SnapDiscoveryURLs []string
+ BscDiscoveryURLs []string
// State options.
NoPruning bool // Whether to disable pruning and flush everything to disk
@@ -109,7 +107,6 @@ type Config struct {
DirectBroadcast bool
DisableSnapProtocol bool // Whether disable snap protocol
- EnableTrustProtocol bool // Whether enable trust protocol
RangeLimit bool
// Deprecated: use 'TransactionHistory' instead.
@@ -136,9 +133,6 @@ type Config struct {
DatabaseHandles int `toml:"-"`
DatabaseCache int
DatabaseFreezer string
- DatabaseDiff string
- PersistDiff bool
- DiffBlock uint64
// PruneAncientData is an optional config and disabled by default, and usually you do not need it.
// When this flag is enabled, only keep the latest 9w blocks' data, the older blocks' data will be
// pruned instead of being dumped to freezerdb, the pruned data includes CanonicalHash, Header, Block,
diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go
index 48514e8c93..26f261ee30 100644
--- a/eth/ethconfig/gen_config.go
+++ b/eth/ethconfig/gen_config.go
@@ -25,13 +25,11 @@ func (c Config) MarshalTOML() (interface{}, error) {
EVNNodeIDsToRemove []enode.ID
EthDiscoveryURLs []string
SnapDiscoveryURLs []string
- TrustDiscoveryURLs []string
BscDiscoveryURLs []string
NoPruning bool
NoPrefetch bool
DirectBroadcast bool
DisableSnapProtocol bool
- EnableTrustProtocol bool
RangeLimit bool
TxLookupLimit uint64 `toml:",omitempty"`
TransactionHistory uint64 `toml:",omitempty"`
@@ -45,9 +43,6 @@ func (c Config) MarshalTOML() (interface{}, error) {
DatabaseHandles int `toml:"-"`
DatabaseCache int
DatabaseFreezer string
- DatabaseDiff string
- PersistDiff bool
- DiffBlock uint64
PruneAncientData bool
TrieCleanCache int
TrieDirtyCache int
@@ -83,13 +78,11 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.EVNNodeIDsToRemove = c.EVNNodeIDsToRemove
enc.EthDiscoveryURLs = c.EthDiscoveryURLs
enc.SnapDiscoveryURLs = c.SnapDiscoveryURLs
- enc.TrustDiscoveryURLs = c.TrustDiscoveryURLs
enc.BscDiscoveryURLs = c.BscDiscoveryURLs
enc.NoPruning = c.NoPruning
enc.NoPrefetch = c.NoPrefetch
enc.DirectBroadcast = c.DirectBroadcast
enc.DisableSnapProtocol = c.DisableSnapProtocol
- enc.EnableTrustProtocol = c.EnableTrustProtocol
enc.RangeLimit = c.RangeLimit
enc.TxLookupLimit = c.TxLookupLimit
enc.TransactionHistory = c.TransactionHistory
@@ -103,9 +96,6 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.DatabaseHandles = c.DatabaseHandles
enc.DatabaseCache = c.DatabaseCache
enc.DatabaseFreezer = c.DatabaseFreezer
- enc.DatabaseDiff = c.DatabaseDiff
- enc.PersistDiff = c.PersistDiff
- enc.DiffBlock = c.DiffBlock
enc.PruneAncientData = c.PruneAncientData
enc.TrieCleanCache = c.TrieCleanCache
enc.TrieDirtyCache = c.TrieDirtyCache
@@ -145,13 +135,11 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
EVNNodeIDsToRemove []enode.ID
EthDiscoveryURLs []string
SnapDiscoveryURLs []string
- TrustDiscoveryURLs []string
BscDiscoveryURLs []string
NoPruning *bool
NoPrefetch *bool
DirectBroadcast *bool
DisableSnapProtocol *bool
- EnableTrustProtocol *bool
RangeLimit *bool
TxLookupLimit *uint64 `toml:",omitempty"`
TransactionHistory *uint64 `toml:",omitempty"`
@@ -165,9 +153,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
DatabaseHandles *int `toml:"-"`
DatabaseCache *int
DatabaseFreezer *string
- DatabaseDiff *string
- PersistDiff *bool
- DiffBlock *uint64
PruneAncientData *bool
TrieCleanCache *int
TrieDirtyCache *int
@@ -222,9 +207,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.SnapDiscoveryURLs != nil {
c.SnapDiscoveryURLs = dec.SnapDiscoveryURLs
}
- if dec.TrustDiscoveryURLs != nil {
- c.TrustDiscoveryURLs = dec.TrustDiscoveryURLs
- }
if dec.BscDiscoveryURLs != nil {
c.BscDiscoveryURLs = dec.BscDiscoveryURLs
}
@@ -240,9 +222,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.DisableSnapProtocol != nil {
c.DisableSnapProtocol = *dec.DisableSnapProtocol
}
- if dec.EnableTrustProtocol != nil {
- c.EnableTrustProtocol = *dec.EnableTrustProtocol
- }
if dec.RangeLimit != nil {
c.RangeLimit = *dec.RangeLimit
}
@@ -282,15 +261,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.DatabaseFreezer != nil {
c.DatabaseFreezer = *dec.DatabaseFreezer
}
- if dec.DatabaseDiff != nil {
- c.DatabaseDiff = *dec.DatabaseDiff
- }
- if dec.PersistDiff != nil {
- c.PersistDiff = *dec.PersistDiff
- }
- if dec.DiffBlock != nil {
- c.DiffBlock = *dec.DiffBlock
- }
if dec.PruneAncientData != nil {
c.PruneAncientData = *dec.PruneAncientData
}
diff --git a/eth/handler.go b/eth/handler.go
index a2bf8f7399..92885604dc 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -42,7 +42,6 @@ import (
"github.com/ethereum/go-ethereum/eth/protocols/bsc"
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
- "github.com/ethereum/go-ethereum/eth/protocols/trust"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
@@ -443,11 +442,6 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error {
peer.Log().Error("Snapshot extension barrier failed", "err", err)
return err
}
- trust, err := h.peers.waitTrustExtension(peer)
- if err != nil {
- peer.Log().Error("Trust extension barrier failed", "err", err)
- return err
- }
bsc, err := h.peers.waitBscExtension(peer)
if err != nil {
peer.Log().Error("Bsc extension barrier failed", "err", err)
@@ -505,7 +499,7 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error {
}
// Register the peer locally
- if err := h.peers.registerPeer(peer, snap, trust, bsc); err != nil {
+ if err := h.peers.registerPeer(peer, snap, bsc); err != nil {
peer.Log().Error("Ethereum peer registration failed", "err", err)
return err
}
@@ -610,30 +604,6 @@ func (h *handler) runSnapExtension(peer *snap.Peer, handler snap.Handler) error
return handler(peer)
}
-// runTrustExtension registers a `trust` peer into the joint eth/trust peerset and
-// starts handling inbound messages. As `trust` is only a satellite protocol to
-// `eth`, all subsystem registrations and lifecycle management will be done by
-// the main `eth` handler to prevent strange races.
-func (h *handler) runTrustExtension(peer *trust.Peer, handler trust.Handler) error {
- if !h.incHandlers() {
- return p2p.DiscQuitting
- }
- defer h.decHandlers()
-
- if err := h.peers.registerTrustExtension(peer); err != nil {
- if metrics.Enabled() {
- if peer.Inbound() {
- trust.IngressRegistrationErrorMeter.Mark(1)
- } else {
- trust.EgressRegistrationErrorMeter.Mark(1)
- }
- }
- peer.Log().Error("Trust extension registration failed", "err", err)
- return err
- }
- return handler(peer)
-}
-
// runBscExtension registers a `bsc` peer into the joint eth/bsc peerset and
// starts handling inbound messages. As `bsc` is only a satellite protocol to
// `eth`, all subsystem registrations and lifecycle management will be done by
diff --git a/eth/handler_trust.go b/eth/handler_trust.go
deleted file mode 100644
index e470c5316b..0000000000
--- a/eth/handler_trust.go
+++ /dev/null
@@ -1,53 +0,0 @@
-package eth
-
-import (
- "errors"
- "fmt"
-
- "github.com/ethereum/go-ethereum/core"
- "github.com/ethereum/go-ethereum/eth/protocols/trust"
- "github.com/ethereum/go-ethereum/p2p/enode"
-)
-
-// trustHandler implements the trust.Backend interface to handle the various network
-// packets that are sent as replies or broadcasts.
-type trustHandler handler
-
-func (h *trustHandler) Chain() *core.BlockChain { return h.chain }
-
-// RunPeer is invoked when a peer joins on the `snap` protocol.
-func (h *trustHandler) RunPeer(peer *trust.Peer, hand trust.Handler) error {
- return (*handler)(h).runTrustExtension(peer, hand)
-}
-
-// PeerInfo retrieves all known `trust` information about a peer.
-func (h *trustHandler) PeerInfo(id enode.ID) interface{} {
- if p := h.peers.peer(id.String()); p != nil {
- if p.trustExt != nil {
- return p.trustExt.info()
- }
- }
- return nil
-}
-
-// Handle is invoked from a peer's message handler when it receives a new remote
-// message that the handler couldn't consume and serve itself.
-func (h *trustHandler) Handle(peer *trust.Peer, packet trust.Packet) error {
- switch packet := packet.(type) {
- case *trust.RootResponsePacket:
- verifyResult := &core.VerifyResult{
- Status: packet.Status,
- BlockNumber: packet.BlockNumber,
- BlockHash: packet.BlockHash,
- Root: packet.Root,
- }
- if vm := h.Chain().Validator().RemoteVerifyManager(); vm != nil {
- vm.HandleRootResponse(verifyResult, peer.ID())
- return nil
- }
- return errors.New("verify manager is nil which is unexpected")
-
- default:
- return fmt.Errorf("unexpected trust packet type: %T", packet)
- }
-}
diff --git a/eth/peer.go b/eth/peer.go
index 3125753047..5647cfcdbe 100644
--- a/eth/peer.go
+++ b/eth/peer.go
@@ -20,8 +20,6 @@ import (
"net"
"github.com/ethereum/go-ethereum/eth/protocols/bsc"
- "github.com/ethereum/go-ethereum/eth/protocols/trust"
-
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
)
@@ -35,9 +33,8 @@ type ethPeerInfo struct {
// ethPeer is a wrapper around eth.Peer to maintain a few extra metadata.
type ethPeer struct {
*eth.Peer
- snapExt *snapPeer // Satellite `snap` connection
- trustExt *trustPeer
- bscExt *bscPeer // Satellite `bsc` connection
+ snapExt *snapPeer // Satellite `snap` connection
+ bscExt *bscPeer // Satellite `bsc` connection
}
// info gathers and returns some `eth` protocol metadata known about a peer.
@@ -60,12 +57,6 @@ type snapPeerInfo struct {
Version uint `json:"version"` // Snapshot protocol version negotiated
}
-// trustPeerInfo represents a short summary of the `trust` sub-protocol metadata known
-// about a connected peer.
-type trustPeerInfo struct {
- Version uint `json:"version"` // Trust protocol version negotiated
-}
-
// bscPeerInfo represents a short summary of the `bsc` sub-protocol metadata known
// about a connected peer.
type bscPeerInfo struct {
@@ -77,11 +68,6 @@ type snapPeer struct {
*snap.Peer
}
-// trustPeer is a wrapper around trust.Peer to maintain a few extra metadata.
-type trustPeer struct {
- *trust.Peer
-}
-
// bscPeer is a wrapper around bsc.Peer to maintain a few extra metadata.
type bscPeer struct {
*bsc.Peer
@@ -94,13 +80,6 @@ func (p *snapPeer) info() *snapPeerInfo {
}
}
-// info gathers and returns some `trust` protocol metadata known about a peer.
-func (p *trustPeer) info() *trustPeerInfo {
- return &trustPeerInfo{
- Version: p.Version(),
- }
-}
-
// info gathers and returns some `bsc` protocol metadata known about a peer.
func (p *bscPeer) info() *bscPeerInfo {
return &bscPeerInfo{
diff --git a/eth/peerset.go b/eth/peerset.go
index d3617ec892..32a0839d62 100644
--- a/eth/peerset.go
+++ b/eth/peerset.go
@@ -24,11 +24,9 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth/protocols/bsc"
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
- "github.com/ethereum/go-ethereum/eth/protocols/trust"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p"
@@ -55,10 +53,6 @@ var (
// snap protocol without advertising the eth main protocol.
errSnapWithoutEth = errors.New("peer connected on snap without compatible eth support")
- // errTrustWithoutEth is returned if a peer attempts to connect only on the
- // trust protocol without advertising the eth main protocol.
- errTrustWithoutEth = errors.New("peer connected on trust without compatible eth support")
-
// errBscWithoutEth is returned if a peer attempts to connect only on the
// bsc protocol without advertising the eth main protocol.
errBscWithoutEth = errors.New("peer connected on bsc without compatible eth support")
@@ -87,9 +81,6 @@ type peerSet struct {
snapWait map[string]chan *snap.Peer // Peers connected on `eth` waiting for their snap extension
snapPend map[string]*snap.Peer // Peers connected on the `snap` protocol, but not yet on `eth`
- trustWait map[string]chan *trust.Peer // Peers connected on `eth` waiting for their trust extension
- trustPend map[string]*trust.Peer // Peers connected on the `trust` protocol, but not yet on `eth`
-
bscWait map[string]chan *bsc.Peer // Peers connected on `eth` waiting for their bsc extension
bscPend map[string]*bsc.Peer // Peers connected on the `bsc` protocol, but not yet on `eth`
@@ -101,14 +92,12 @@ type peerSet struct {
// newPeerSet creates a new peer set to track the active participants.
func newPeerSet() *peerSet {
return &peerSet{
- peers: make(map[string]*ethPeer),
- snapWait: make(map[string]chan *snap.Peer),
- snapPend: make(map[string]*snap.Peer),
- trustWait: make(map[string]chan *trust.Peer),
- trustPend: make(map[string]*trust.Peer),
- bscWait: make(map[string]chan *bsc.Peer),
- bscPend: make(map[string]*bsc.Peer),
- quitCh: make(chan struct{}),
+ peers: make(map[string]*ethPeer),
+ snapWait: make(map[string]chan *snap.Peer),
+ snapPend: make(map[string]*snap.Peer),
+ bscWait: make(map[string]chan *bsc.Peer),
+ bscPend: make(map[string]*bsc.Peer),
+ quitCh: make(chan struct{}),
}
}
@@ -142,40 +131,6 @@ func (ps *peerSet) registerSnapExtension(peer *snap.Peer) error {
return nil
}
-// registerTrustExtension unblocks an already connected `eth` peer waiting for its
-// `trust` extension, or if no such peer exists, tracks the extension for the time
-// being until the `eth` main protocol starts looking for it.
-func (ps *peerSet) registerTrustExtension(peer *trust.Peer) error {
- // Reject the peer if it advertises `trust` without `eth` as `trust` is only a
- // satellite protocol meaningful with the chain selection of `eth`
- if !peer.RunningCap(eth.ProtocolName, eth.ProtocolVersions) {
- return errTrustWithoutEth
- }
- // If the peer isn't verify node, don't register trust extension into eth protocol.
- if !peer.VerifyNode() {
- return nil
- }
- // Ensure nobody can double connect
- ps.lock.Lock()
- defer ps.lock.Unlock()
-
- id := peer.ID()
- if _, ok := ps.peers[id]; ok {
- return errPeerAlreadyRegistered // avoid connections with the same id as existing ones
- }
- if _, ok := ps.trustPend[id]; ok {
- return errPeerAlreadyRegistered // avoid connections with the same id as pending ones
- }
- // Inject the peer into an `eth` counterpart is available, otherwise save for later
- if wait, ok := ps.trustWait[id]; ok {
- delete(ps.trustWait, id)
- wait <- peer
- return nil
- }
- ps.trustPend[id] = peer
- return nil
-}
-
// registerBscExtension unblocks an already connected `eth` peer waiting for its
// `bsc` extension, or if no such peer exists, tracks the extension for the time
// being until the `eth` main protocol starts looking for it.
@@ -255,59 +210,6 @@ func (ps *peerSet) waitSnapExtension(peer *eth.Peer) (*snap.Peer, error) {
}
}
-// waitTrustExtension blocks until all satellite protocols are connected and tracked
-// by the peerset.
-func (ps *peerSet) waitTrustExtension(peer *eth.Peer) (*trust.Peer, error) {
- // If the peer does not support a compatible `trust`, don't wait
- if !peer.RunningCap(trust.ProtocolName, trust.ProtocolVersions) {
- return nil, nil
- }
- // If the peer isn't verify node, don't register trust extension into eth protocol.
- if !peer.VerifyNode() {
- return nil, nil
- }
- // Ensure nobody can double connect
- ps.lock.Lock()
-
- id := peer.ID()
- if _, ok := ps.peers[id]; ok {
- ps.lock.Unlock()
- return nil, errPeerAlreadyRegistered // avoid connections with the same id as existing ones
- }
- if _, ok := ps.trustWait[id]; ok {
- ps.lock.Unlock()
- return nil, errPeerAlreadyRegistered // avoid connections with the same id as pending ones
- }
- // If `trust` already connected, retrieve the peer from the pending set
- if trust, ok := ps.trustPend[id]; ok {
- delete(ps.trustPend, id)
-
- ps.lock.Unlock()
- return trust, nil
- }
- // Otherwise wait for `trust` to connect concurrently
- wait := make(chan *trust.Peer)
- ps.trustWait[id] = wait
- ps.lock.Unlock()
-
- select {
- case peer := <-wait:
- return peer, nil
-
- case <-time.After(extensionWaitTimeout):
- ps.lock.Lock()
- delete(ps.trustWait, id)
- ps.lock.Unlock()
- return nil, errPeerWaitTimeout
-
- case <-ps.quitCh:
- ps.lock.Lock()
- delete(ps.trustWait, id)
- ps.lock.Unlock()
- return nil, errPeerSetClosed
- }
-}
-
// waitBscExtension blocks until all satellite protocols are connected and tracked
// by the peerset.
func (ps *peerSet) waitBscExtension(peer *eth.Peer) (*bsc.Peer, error) {
@@ -373,23 +275,9 @@ func (ps *peerSet) waitBscExtension(peer *eth.Peer) (*bsc.Peer, error) {
}
}
-// GetVerifyPeers returns an array of verify nodes.
-func (ps *peerSet) GetVerifyPeers() []core.VerifyPeer {
- ps.lock.RLock()
- defer ps.lock.RUnlock()
-
- res := make([]core.VerifyPeer, 0)
- for _, p := range ps.peers {
- if p.trustExt != nil && p.trustExt.Peer != nil {
- res = append(res, p.trustExt.Peer)
- }
- }
- return res
-}
-
// registerPeer injects a new `eth` peer into the working set, or returns an error
// if the peer is already known.
-func (ps *peerSet) registerPeer(peer *eth.Peer, ext *snap.Peer, trustExt *trust.Peer, bscExt *bsc.Peer) error {
+func (ps *peerSet) registerPeer(peer *eth.Peer, ext *snap.Peer, bscExt *bsc.Peer) error {
// Start tracking the new peer
ps.lock.Lock()
defer ps.lock.Unlock()
@@ -408,9 +296,6 @@ func (ps *peerSet) registerPeer(peer *eth.Peer, ext *snap.Peer, trustExt *trust.
eth.snapExt = &snapPeer{ext}
ps.snapPeers++
}
- if trustExt != nil {
- eth.trustExt = &trustPeer{trustExt}
- }
if bscExt != nil {
eth.bscExt = &bscPeer{bscExt}
}
diff --git a/eth/protocols/trust/discovery.go b/eth/protocols/trust/discovery.go
deleted file mode 100644
index ce38ec5ed9..0000000000
--- a/eth/protocols/trust/discovery.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package trust
-
-import "github.com/ethereum/go-ethereum/rlp"
-
-// enrEntry is the ENR entry which advertises `trust` protocol on the discovery.
-type enrEntry struct {
- // Ignore additional fields (for forward compatibility).
- Rest []rlp.RawValue `rlp:"tail"`
-}
-
-// ENRKey implements enr.Entry.
-func (e enrEntry) ENRKey() string {
- return "trust"
-}
diff --git a/eth/protocols/trust/handler.go b/eth/protocols/trust/handler.go
deleted file mode 100644
index 48ef4b7fbf..0000000000
--- a/eth/protocols/trust/handler.go
+++ /dev/null
@@ -1,148 +0,0 @@
-package trust
-
-import (
- "fmt"
- "time"
-
- "github.com/ethereum/go-ethereum/core"
- "github.com/ethereum/go-ethereum/metrics"
- "github.com/ethereum/go-ethereum/p2p"
- "github.com/ethereum/go-ethereum/p2p/enode"
- "github.com/ethereum/go-ethereum/p2p/enr"
-)
-
-// Handler is a callback to invoke from an outside runner after the boilerplate
-// exchanges have passed.
-type Handler func(peer *Peer) error
-
-type Backend interface {
- // Chain retrieves the blockchain object to serve data.
- Chain() *core.BlockChain
-
- // RunPeer is invoked when a peer joins on the `eth` protocol. The handler
- // should do any peer maintenance work, handshakes and validations. If all
- // is passed, control should be given back to the `handler` to process the
- // inbound messages going forward.
- RunPeer(peer *Peer, handler Handler) error
-
- PeerInfo(id enode.ID) interface{}
-
- Handle(peer *Peer, packet Packet) error
-}
-
-// MakeProtocols constructs the P2P protocol definitions for `trust`.
-func MakeProtocols(backend Backend) []p2p.Protocol {
- protocols := make([]p2p.Protocol, len(ProtocolVersions))
- for i, version := range ProtocolVersions {
- protocols[i] = p2p.Protocol{
- Name: ProtocolName,
- Version: version,
- Length: protocolLengths[version],
- Run: func(p *p2p.Peer, rw p2p.MsgReadWriter) error {
- return backend.RunPeer(NewPeer(version, p, rw), func(peer *Peer) error {
- defer peer.Close()
- return Handle(backend, peer)
- })
- },
- NodeInfo: func() interface{} {
- return nodeInfo(backend.Chain())
- },
- PeerInfo: func(id enode.ID) interface{} {
- return backend.PeerInfo(id)
- },
- Attributes: []enr.Entry{&enrEntry{}},
- }
- }
- return protocols
-}
-
-// Handle is the callback invoked to manage the life cycle of a `trust` peer.
-// When this function terminates, the peer is disconnected.
-func Handle(backend Backend, peer *Peer) error {
- for {
- if err := handleMessage(backend, peer); err != nil {
- peer.Log().Debug("Message handling failed in `trust`", "err", err)
- return err
- }
- }
-}
-
-// handleMessage is invoked whenever an inbound message is received from a
-// remote peer on the `trust` protocol. The remote connection is torn down upon
-// returning any error.
-func handleMessage(backend Backend, peer *Peer) error {
- // Read the next message from the remote peer, and ensure it's fully consumed
- msg, err := peer.rw.ReadMsg()
- if err != nil {
- return err
- }
- if msg.Size > maxMessageSize {
- return fmt.Errorf("%w: %v > %v", errMsgTooLarge, msg.Size, maxMessageSize)
- }
- defer msg.Discard()
-
- // Track the amount of time it takes to serve the request and run the handler
- if metrics.Enabled() {
- h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
- defer func(start time.Time) {
- sampler := func() metrics.Sample {
- return metrics.ResettingSample(
- metrics.NewExpDecaySample(1028, 0.015),
- )
- }
- metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(time.Since(start).Microseconds())
- }(time.Now())
- }
- // Handle the message depending on its contents
- switch {
- case msg.Code == RequestRootMsg:
- return handleRootRequest(backend, msg, peer)
-
- case msg.Code == RespondRootMsg:
- return handleRootResponse(backend, msg, peer)
-
- default:
- return fmt.Errorf("%w: %v", errInvalidMsgCode, msg.Code)
- }
-}
-
-type Decoder interface {
- Decode(val interface{}) error
- Time() time.Time
-}
-
-func handleRootRequest(backend Backend, msg Decoder, peer *Peer) error {
- req := new(RootRequestPacket)
- if err := msg.Decode(req); err != nil {
- return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
- }
-
- res := backend.Chain().GetVerifyResult(req.BlockNumber, req.BlockHash, req.DiffHash)
- return p2p.Send(peer.rw, RespondRootMsg, RootResponsePacket{
- RequestId: req.RequestId,
- Status: res.Status,
- BlockNumber: req.BlockNumber,
- BlockHash: req.BlockHash,
- Root: res.Root,
- Extra: defaultExtra,
- })
-}
-
-func handleRootResponse(backend Backend, msg Decoder, peer *Peer) error {
- res := new(RootResponsePacket)
- if err := msg.Decode(res); err != nil {
- return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
- }
-
- requestTracker.Fulfil(peer.id, peer.version, RespondRootMsg, res.RequestId)
- return backend.Handle(peer, res)
-}
-
-// NodeInfo represents a short summary of the `trust` sub-protocol metadata
-// known about the host peer.
-type NodeInfo struct{}
-
-// nodeInfo retrieves some `trust` protocol metadata about the running host node.
-func nodeInfo(chain *core.BlockChain) *NodeInfo {
- return &NodeInfo{}
-}
diff --git a/eth/protocols/trust/handler_test.go b/eth/protocols/trust/handler_test.go
deleted file mode 100644
index 187b29c932..0000000000
--- a/eth/protocols/trust/handler_test.go
+++ /dev/null
@@ -1,273 +0,0 @@
-package trust
-
-import (
- "math/big"
- "testing"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/consensus/clique"
- "github.com/ethereum/go-ethereum/core"
- "github.com/ethereum/go-ethereum/core/rawdb"
- "github.com/ethereum/go-ethereum/core/txpool/legacypool"
- "github.com/ethereum/go-ethereum/core/types"
- "github.com/ethereum/go-ethereum/core/vm"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/p2p"
- "github.com/ethereum/go-ethereum/p2p/enode"
- "github.com/ethereum/go-ethereum/params"
- "github.com/ethereum/go-ethereum/triedb"
-)
-
-var (
- // testKey is a private key to use for funding a tester account.
- testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
-
- // testAddr is the Ethereum address of the tester account.
- testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
-)
-
-// 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.
-type testBackend struct {
- db ethdb.Database
- chain *core.BlockChain
- txpool *legacypool.LegacyPool
-}
-
-// newTestBackend creates an empty chain and wraps it into a mock backend.
-func newTestBackend(blocks int) *testBackend {
- return newTestBackendWithGenerator(blocks)
-}
-
-// newTestBackend creates a chain with a number of explicitly defined blocks and
-// wraps it into a mock backend.
-func newTestBackendWithGenerator(blocks int) *testBackend {
- signer := types.HomesteadSigner{}
- db := rawdb.NewMemoryDatabase()
- engine := clique.New(params.AllCliqueProtocolChanges.Clique, db)
- genspec := &core.Genesis{
- Config: params.AllCliqueProtocolChanges,
- ExtraData: make([]byte, 32+common.AddressLength+65),
- Alloc: types.GenesisAlloc{testAddr: {Balance: big.NewInt(100000000000000000)}},
- BaseFee: big.NewInt(0),
- }
- copy(genspec.ExtraData[32:], testAddr[:])
- genesis := genspec.MustCommit(db, triedb.NewDatabase(db, nil))
-
- chain, _ := core.NewBlockChain(db, nil, genspec, nil, engine, vm.Config{}, nil, nil)
- generator := func(i int, block *core.BlockGen) {
- // The chain maker doesn't have access to a chain, so the difficulty will be
- // lets unset (nil). Set it here to the correct value.
- // block.SetCoinbase(testAddr)
- block.SetDifficulty(big.NewInt(2))
-
- // We want to simulate an empty middle block, having the same state as the
- // first one. The last is needs a state change again to force a reorg.
- tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddr), common.Address{0x01}, big.NewInt(1), params.TxGas, nil, nil), signer, testKey)
- if err != nil {
- panic(err)
- }
- block.AddTxWithChain(chain, tx)
- }
-
- bs, _ := core.GenerateChain(params.AllCliqueProtocolChanges, genesis, engine, db, blocks, generator)
- for i, block := range bs {
- header := block.Header()
- if i > 0 {
- header.ParentHash = bs[i-1].Hash()
- }
- header.Extra = make([]byte, 32+65)
- header.Difficulty = big.NewInt(2)
-
- sig, _ := crypto.Sign(clique.SealHash(header).Bytes(), testKey)
- copy(header.Extra[len(header.Extra)-65:], sig)
- bs[i] = block.WithSeal(header)
- }
-
- if _, err := chain.InsertChain(bs); err != nil {
- panic(err)
- }
-
- txconfig := legacypool.DefaultConfig
- txconfig.Journal = "" // Don't litter the disk with test journals
-
- return &testBackend{
- db: db,
- chain: chain,
- txpool: legacypool.New(txconfig, chain),
- }
-}
-
-// close tears down the transaction pool and chain behind the mock backend.
-func (b *testBackend) close() {
- b.txpool.Close()
- b.chain.Stop()
-}
-
-func (b *testBackend) Chain() *core.BlockChain { return b.chain }
-
-func (b *testBackend) RunPeer(peer *Peer, handler Handler) error {
- // Normally the backend would do peer mainentance and handshakes. All that
- // is omitted and we will just give control back to the handler.
- return handler(peer)
-}
-func (b *testBackend) PeerInfo(enode.ID) interface{} { panic("not implemented") }
-
-func (b *testBackend) Handle(*Peer, Packet) error {
- panic("data processing tests should be done in the handler package")
-}
-
-func TestRequestRoot(t *testing.T) { testRequestRoot(t, Trust1) }
-
-func testRequestRoot(t *testing.T, protocol uint) {
- t.Parallel()
-
- blockNum := 1032 // The latest 1024 blocks' DiffLayer will be cached.
- backend := newTestBackend(blockNum)
- defer backend.close()
-
- peer, _ := newTestPeer("peer", protocol, backend)
- defer peer.close()
-
- pairs := []struct {
- req RootRequestPacket
- res RootResponsePacket
- }{
- {
- req: RootRequestPacket{
- RequestId: 1,
- BlockNumber: 1,
- },
- res: RootResponsePacket{
- RequestId: 1,
- Status: types.StatusPartiallyVerified,
- BlockNumber: 1,
- Extra: defaultExtra,
- },
- },
- {
- req: RootRequestPacket{
- RequestId: 2,
- BlockNumber: 128,
- },
- res: RootResponsePacket{
- RequestId: 2,
- Status: types.StatusFullVerified,
- BlockNumber: 128,
- Extra: defaultExtra,
- },
- },
- {
- req: RootRequestPacket{
- RequestId: 3,
- BlockNumber: 128,
- BlockHash: types.EmptyRootHash,
- DiffHash: types.EmptyRootHash,
- },
- res: RootResponsePacket{
- RequestId: 3,
- Status: types.StatusImpossibleFork,
- BlockNumber: 128,
- BlockHash: types.EmptyRootHash,
- Root: common.Hash{},
- Extra: defaultExtra,
- },
- },
- {
- req: RootRequestPacket{
- RequestId: 4,
- BlockNumber: 128,
- DiffHash: types.EmptyRootHash,
- },
- res: RootResponsePacket{
- RequestId: 4,
- Status: types.StatusDiffHashMismatch,
- BlockNumber: 128,
- Root: common.Hash{},
- Extra: defaultExtra,
- },
- },
- {
- req: RootRequestPacket{
- RequestId: 5,
- BlockNumber: 1024,
- },
- res: RootResponsePacket{
- RequestId: 5,
- Status: types.StatusFullVerified,
- BlockNumber: 1024,
- Extra: defaultExtra,
- },
- },
- {
- req: RootRequestPacket{
- RequestId: 6,
- BlockNumber: 1024,
- BlockHash: types.EmptyRootHash,
- DiffHash: types.EmptyRootHash,
- },
- res: RootResponsePacket{
- RequestId: 6,
- Status: types.StatusPossibleFork,
- BlockNumber: 1024,
- BlockHash: types.EmptyRootHash,
- Root: common.Hash{},
- Extra: defaultExtra,
- },
- },
- {
- req: RootRequestPacket{
- RequestId: 7,
- BlockNumber: 1033,
- BlockHash: types.EmptyRootHash,
- DiffHash: types.EmptyRootHash,
- },
- res: RootResponsePacket{
- RequestId: 7,
- Status: types.StatusBlockNewer,
- BlockNumber: 1033,
- BlockHash: types.EmptyRootHash,
- Root: common.Hash{},
- Extra: defaultExtra,
- },
- },
- {
- req: RootRequestPacket{
- RequestId: 8,
- BlockNumber: 1044,
- BlockHash: types.EmptyRootHash,
- DiffHash: types.EmptyRootHash,
- },
- res: RootResponsePacket{
- RequestId: 8,
- Status: types.StatusBlockTooNew,
- BlockNumber: 1044,
- BlockHash: types.EmptyRootHash,
- Root: common.Hash{},
- Extra: defaultExtra,
- },
- },
- }
-
- for idx, pair := range pairs {
- header := backend.Chain().GetHeaderByNumber(pair.req.BlockNumber)
- if header != nil {
- if pair.res.Status.Code&0xFF00 == types.StatusVerified.Code {
- pair.req.BlockHash = header.Hash()
- pair.req.DiffHash, _ = core.CalculateDiffHash(backend.Chain().GetTrustedDiffLayer(header.Hash()))
- pair.res.BlockHash = pair.req.BlockHash
- pair.res.Root = header.Root
- } else if pair.res.Status.Code == types.StatusDiffHashMismatch.Code {
- pair.req.BlockHash = header.Hash()
- pair.res.BlockHash = pair.req.BlockHash
- }
- }
-
- p2p.Send(peer.app, RequestRootMsg, pair.req)
- if err := p2p.ExpectMsg(peer.app, RespondRootMsg, pair.res); err != nil {
- t.Errorf("test %d: root response not expected: %v", idx, err)
- }
- }
-}
diff --git a/eth/protocols/trust/metrics.go b/eth/protocols/trust/metrics.go
deleted file mode 100644
index 470c549536..0000000000
--- a/eth/protocols/trust/metrics.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package trust
-
-import (
- metrics "github.com/ethereum/go-ethereum/metrics"
-)
-
-var (
- ingressRegistrationErrorName = "eth/protocols/trust/ingress/registration/error"
- egressRegistrationErrorName = "eth/protocols/trust/egress/registration/error"
-
- IngressRegistrationErrorMeter = metrics.NewRegisteredMeter(ingressRegistrationErrorName, nil)
- EgressRegistrationErrorMeter = metrics.NewRegisteredMeter(egressRegistrationErrorName, nil)
-)
diff --git a/eth/protocols/trust/peer.go b/eth/protocols/trust/peer.go
deleted file mode 100644
index b47341c3cb..0000000000
--- a/eth/protocols/trust/peer.go
+++ /dev/null
@@ -1,66 +0,0 @@
-package trust
-
-import (
- "math/rand"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/p2p"
-)
-
-// Peer is a collection of relevant information we have about a `trust` peer.
-type Peer struct {
- id string // Unique ID for the peer, cached
-
- *p2p.Peer // The embedded P2P package peer
- rw p2p.MsgReadWriter // Input/output streams for diff
- version uint // Protocol version negotiated
- logger log.Logger // Contextual logger with the peer id injected
-}
-
-// NewPeer create a wrapper for a network connection and negotiated protocol
-// version.
-func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
- id := p.ID().String()
- peer := &Peer{
- id: id,
- Peer: p,
- rw: rw,
- version: version,
- logger: log.New("peer", id[:8]),
- }
- return peer
-}
-
-// ID retrieves the peer's unique identifier.
-func (p *Peer) ID() string {
- return p.id
-}
-
-// Version retrieves the peer's negotiated `trust` protocol version.
-func (p *Peer) Version() uint {
- return p.version
-}
-
-// Log overrides the P2P logget with the higher level one containing only the id.
-func (p *Peer) Log() log.Logger {
- return p.logger
-}
-
-// Close signals the broadcast goroutine to terminate. Only ever call this if
-// you created the peer yourself via NewPeer. Otherwise let whoever created it
-// clean it up!
-func (p *Peer) Close() {
-}
-
-func (p *Peer) RequestRoot(blockNumber uint64, blockHash common.Hash, diffHash common.Hash) error {
- id := rand.Uint64()
-
- requestTracker.Track(p.id, p.version, RequestRootMsg, RespondRootMsg, id)
- return p2p.Send(p.rw, RequestRootMsg, RootRequestPacket{
- RequestId: id,
- BlockNumber: blockNumber,
- BlockHash: blockHash,
- DiffHash: diffHash,
- })
-}
diff --git a/eth/protocols/trust/peer_test.go b/eth/protocols/trust/peer_test.go
deleted file mode 100644
index 8883189303..0000000000
--- a/eth/protocols/trust/peer_test.go
+++ /dev/null
@@ -1,42 +0,0 @@
-package trust
-
-import (
- "crypto/rand"
-
- "github.com/ethereum/go-ethereum/p2p"
- "github.com/ethereum/go-ethereum/p2p/enode"
-)
-
-// testPeer is a simulated peer to allow testing direct network calls.
-type testPeer struct {
- *Peer
-
- net p2p.MsgReadWriter // Network layer reader/writer to simulate remote messaging
- app *p2p.MsgPipeRW // Application layer reader/writer to simulate the local side
-}
-
-// newTestPeer creates a new peer registered at the given data backend.
-func newTestPeer(name string, version uint, backend Backend) (*testPeer, <-chan error) {
- // Create a message pipe to communicate through
- app, net := p2p.MsgPipe()
-
- // Start the peer on a new thread
- var id enode.ID
- rand.Read(id[:])
-
- peer := NewPeer(version, p2p.NewPeer(id, name, nil), net)
- errc := make(chan error, 1)
- go func() {
- errc <- backend.RunPeer(peer, func(peer *Peer) error {
- return Handle(backend, peer)
- })
- }()
- return &testPeer{app: app, net: net, Peer: peer}, errc
-}
-
-// close terminates the local side of the peer, notifying the remote protocol
-// manager of termination.
-func (p *testPeer) close() {
- p.Peer.Close()
- p.app.Close()
-}
diff --git a/eth/protocols/trust/protocol.go b/eth/protocols/trust/protocol.go
deleted file mode 100644
index e4f98dd324..0000000000
--- a/eth/protocols/trust/protocol.go
+++ /dev/null
@@ -1,71 +0,0 @@
-package trust
-
-import (
- "errors"
-
- "github.com/ethereum/go-ethereum/core/types"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/rlp"
-)
-
-// Constants to match up protocol versions and messages
-const (
- Trust1 = 1
-)
-
-// ProtocolName is the official short name of the `trust` protocol used during
-// devp2p capability negotiation.
-const ProtocolName = "trust"
-
-// ProtocolVersions are the supported versions of the `trust` protocol (first
-// is primary).
-var ProtocolVersions = []uint{Trust1}
-
-// protocolLengths are the number of implemented message corresponding to
-// different protocol versions.
-var protocolLengths = map[uint]uint64{Trust1: 2}
-
-// maxMessageSize is the maximum cap on the size of a protocol message.
-const maxMessageSize = 10 * 1024 * 1024
-
-const (
- RequestRootMsg = 0x00
- RespondRootMsg = 0x01
-)
-
-var defaultExtra = []byte{0x00}
-
-var (
- errMsgTooLarge = errors.New("message too long")
- errDecode = errors.New("invalid message")
- errInvalidMsgCode = errors.New("invalid message code")
-)
-
-// Packet represents a p2p message in the `trust` protocol.
-type Packet interface {
- Name() string // Name returns a string corresponding to the message type.
- Kind() byte // Kind returns the message type.
-}
-
-type RootRequestPacket struct {
- RequestId uint64
- BlockNumber uint64
- BlockHash common.Hash
- DiffHash common.Hash
-}
-
-type RootResponsePacket struct {
- RequestId uint64
- Status types.VerifyStatus
- BlockNumber uint64
- BlockHash common.Hash
- Root common.Hash
- Extra rlp.RawValue // for extension
-}
-
-func (*RootRequestPacket) Name() string { return "RequestRoot" }
-func (*RootRequestPacket) Kind() byte { return RequestRootMsg }
-
-func (*RootResponsePacket) Name() string { return "RootResponse" }
-func (*RootResponsePacket) Kind() byte { return RespondRootMsg }
diff --git a/eth/protocols/trust/tracker.go b/eth/protocols/trust/tracker.go
deleted file mode 100644
index ab492b3fb8..0000000000
--- a/eth/protocols/trust/tracker.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package trust
-
-import (
- "time"
-
- "github.com/ethereum/go-ethereum/p2p/tracker"
-)
-
-// requestTracker is a singleton tracker for request times.
-var requestTracker = tracker.New(ProtocolName, time.Minute)
diff --git a/eth/state_accessor.go b/eth/state_accessor.go
index eca90d44b0..9d5ee2c2a0 100644
--- a/eth/state_accessor.go
+++ b/eth/state_accessor.go
@@ -159,7 +159,7 @@ func (eth *Ethereum) hashState(ctx context.Context, block *types.Block, reexec u
return nil, nil, fmt.Errorf("processing block %d failed: %v", current.NumberU64(), err)
}
// Finalize the state so any modifications are written to the trie
- root, _, err := statedb.Commit(current.NumberU64(), eth.blockchain.Config().IsEIP158(current.Number()), eth.blockchain.Config().IsCancun(current.Number(), current.Time()))
+ root, err := statedb.Commit(current.NumberU64(), eth.blockchain.Config().IsEIP158(current.Number()), eth.blockchain.Config().IsCancun(current.Number(), current.Time()))
if err != nil {
return nil, nil, fmt.Errorf("stateAtBlock commit failed, number %d root %v: %w",
current.NumberU64(), current.Root().Hex(), err)
diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go
index dca263aa20..0e6fa13e7e 100644
--- a/ethclient/ethclient.go
+++ b/ethclient/ethclient.go
@@ -27,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
- "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
)
@@ -267,12 +266,6 @@ func (ec *Client) FinalizedBlock(ctx context.Context, verifiedValidatorNum int64
return ec.getBlock(ctx, "eth_getFinalizedBlock", verifiedValidatorNum, fullTx)
}
-func (ec *Client) GetRootByDiffHash(ctx context.Context, blockNr *big.Int, blockHash common.Hash, diffHash common.Hash) (*core.VerifyResult, error) {
- var result core.VerifyResult
- err := ec.c.CallContext(ctx, &result, "eth_getRootByDiffHash", toBlockNumArg(blockNr), blockHash, diffHash)
- return &result, err
-}
-
type rpcTransaction struct {
tx *types.Transaction
txExtraInfo
diff --git a/ethclient/ethclient_test.go b/ethclient/ethclient_test.go
index 6fb21245e9..c36c4010b9 100644
--- a/ethclient/ethclient_test.go
+++ b/ethclient/ethclient_test.go
@@ -224,7 +224,7 @@ func generateTestChain() []*types.Block {
// Create a database pre-initialize with a genesis block
db := rawdb.NewMemoryDatabase()
genesis.MustCommit(db, triedb.NewDatabase(db, nil))
- chain, _ := core.NewBlockChain(db, nil, genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil, core.EnablePersistDiff(860000))
+ chain, _ := core.NewBlockChain(db, nil, genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
generate := func(i int, block *core.BlockGen) {
block.OffsetTime(5)
block.SetExtra([]byte("test"))
diff --git a/ethdb/database.go b/ethdb/database.go
index acd0e370c4..6a83beed76 100644
--- a/ethdb/database.go
+++ b/ethdb/database.go
@@ -224,11 +224,6 @@ type AncientStore interface {
io.Closer
}
-type DiffStore interface {
- DiffStore() KeyValueStore
- SetDiffStore(diff KeyValueStore)
-}
-
type StateStore interface {
StateStore() Database
SetStateStore(state Database)
@@ -252,7 +247,6 @@ type ResettableAncientStore interface {
// Database contains all the methods required by the high level database to not
// only access the key-value data store but also the ancient chain store.
type Database interface {
- DiffStore
StateStore
BlockStore
StateStoreReader
diff --git a/ethdb/remotedb/remotedb.go b/ethdb/remotedb/remotedb.go
index aea0dc2fae..4870f625b6 100644
--- a/ethdb/remotedb/remotedb.go
+++ b/ethdb/remotedb/remotedb.go
@@ -102,14 +102,6 @@ func (db *Database) AncientSize(kind string) (uint64, error) {
panic("not supported")
}
-func (db *Database) DiffStore() ethdb.KeyValueStore {
- panic("not supported")
-}
-
-func (db *Database) SetDiffStore(diff ethdb.KeyValueStore) {
- panic("not supported")
-}
-
func (db *Database) StateStore() ethdb.Database {
panic("not supported")
}
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index 24b734180d..f1debcfcfe 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -1174,181 +1174,6 @@ func (api *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs,
return DoEstimateGas(ctx, api.b, args, bNrOrHash, overrides, blockOverrides, api.b.RPCGasCap())
}
-func (api *BlockChainAPI) needToReplay(ctx context.Context, block *types.Block, accounts []common.Address) (bool, error) {
- receipts, err := api.b.GetReceipts(ctx, block.Hash())
- if err != nil || len(receipts) != len(block.Transactions()) {
- return false, fmt.Errorf("receipt incorrect for block number (%d): %v", block.NumberU64(), err)
- }
-
- accountSet := make(map[common.Address]struct{}, len(accounts))
- for _, account := range accounts {
- accountSet[account] = struct{}{}
- }
- spendValueMap := make(map[common.Address]uint64, len(accounts))
- receiveValueMap := make(map[common.Address]uint64, len(accounts))
-
- signer := types.MakeSigner(api.b.ChainConfig(), block.Number(), block.Time())
- for index, tx := range block.Transactions() {
- receipt := receipts[index]
- from, err := types.Sender(signer, tx)
- if err != nil {
- return false, fmt.Errorf("get sender for tx failed: %v", err)
- }
-
- if _, exists := accountSet[from]; exists {
- spendValueMap[from] += receipt.GasUsed * tx.GasPrice().Uint64()
- if receipt.Status == types.ReceiptStatusSuccessful {
- spendValueMap[from] += tx.Value().Uint64()
- }
- }
-
- if tx.To() == nil {
- continue
- }
-
- if _, exists := accountSet[*tx.To()]; exists && receipt.Status == types.ReceiptStatusSuccessful {
- receiveValueMap[*tx.To()] += tx.Value().Uint64()
- }
- }
-
- parent, err := api.b.BlockByHash(ctx, block.ParentHash())
- if err != nil {
- return false, fmt.Errorf("block not found for block number (%d): %v", block.NumberU64()-1, err)
- }
- parentState, err := api.b.Chain().StateAt(parent.Root())
- if err != nil {
- return false, fmt.Errorf("statedb not found for block number (%d): %v", block.NumberU64()-1, err)
- }
- currentState, err := api.b.Chain().StateAt(block.Root())
- if err != nil {
- return false, fmt.Errorf("statedb not found for block number (%d): %v", block.NumberU64(), err)
- }
- for _, account := range accounts {
- parentBalance := parentState.GetBalance(account).Uint64()
- currentBalance := currentState.GetBalance(account).Uint64()
- if receiveValueMap[account]-spendValueMap[account] != currentBalance-parentBalance {
- return true, nil
- }
- }
-
- return false, nil
-}
-
-func (api *BlockChainAPI) replay(ctx context.Context, block *types.Block, accounts []common.Address) (*types.DiffAccountsInBlock, *state.StateDB, error) {
- result := &types.DiffAccountsInBlock{
- Number: block.NumberU64(),
- BlockHash: block.Hash(),
- Transactions: make([]types.DiffAccountsInTx, 0),
- }
-
- parent, err := api.b.BlockByHash(ctx, block.ParentHash())
- if err != nil {
- return nil, nil, fmt.Errorf("block not found for block number (%d): %v", block.NumberU64()-1, err)
- }
- statedb, err := api.b.Chain().StateAt(parent.Root())
- if err != nil {
- return nil, nil, fmt.Errorf("state not found for block number (%d): %v", block.NumberU64()-1, err)
- }
-
- accountSet := make(map[common.Address]struct{}, len(accounts))
- for _, account := range accounts {
- accountSet[account] = struct{}{}
- }
-
- // Recompute transactions.
- signer := types.MakeSigner(api.b.ChainConfig(), block.Number(), block.Time())
- for _, tx := range block.Transactions() {
- // Skip data empty tx and to is one of the interested accounts tx.
- skip := false
- if len(tx.Data()) == 0 {
- skip = true
- } else if to := tx.To(); to != nil {
- if _, exists := accountSet[*to]; exists {
- skip = true
- }
- }
-
- diffTx := types.DiffAccountsInTx{
- TxHash: tx.Hash(),
- Accounts: make(map[common.Address]*big.Int, len(accounts)),
- }
-
- if !skip {
- // Record account balance
- for _, account := range accounts {
- diffTx.Accounts[account] = statedb.GetBalance(account).ToBig()
- }
- }
-
- // Apply transaction
- msg, _ := core.TransactionToMessage(tx, signer, parent.Header().BaseFee)
- context := core.NewEVMBlockContext(block.Header(), api.b.Chain(), nil)
- evm := vm.NewEVM(context, statedb, api.b.ChainConfig(), vm.Config{})
-
- if posa, ok := api.b.Engine().(consensus.PoSA); ok {
- if isSystem, _ := posa.IsSystemTransaction(tx, block.Header()); isSystem {
- balance := statedb.GetBalance(consensus.SystemAddress)
- if balance.Cmp(common.U2560) > 0 {
- statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0), tracing.BalanceChangeUnspecified)
- statedb.AddBalance(block.Header().Coinbase, balance, tracing.BalanceChangeUnspecified)
- }
- }
- }
-
- if _, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {
- return nil, nil, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
- }
- statedb.Finalise(evm.ChainConfig().IsEIP158(block.Number()))
-
- if !skip {
- // Compute account balance diff.
- for _, account := range accounts {
- diffTx.Accounts[account] = new(big.Int).Sub(statedb.GetBalance(account).ToBig(), diffTx.Accounts[account])
- if diffTx.Accounts[account].Cmp(big.NewInt(0)) == 0 {
- delete(diffTx.Accounts, account)
- }
- }
-
- if len(diffTx.Accounts) != 0 {
- result.Transactions = append(result.Transactions, diffTx)
- }
- }
- }
-
- return result, statedb, nil
-}
-
-// GetDiffAccountsWithScope returns detailed changes of some interested accounts in a specific block number.
-func (api *BlockChainAPI) GetDiffAccountsWithScope(ctx context.Context, blockNr rpc.BlockNumber, accounts []common.Address) (*types.DiffAccountsInBlock, error) {
- if api.b.Chain() == nil {
- return nil, errors.New("blockchain not support get diff accounts")
- }
-
- block, err := api.b.BlockByNumber(ctx, blockNr)
- if err != nil {
- return nil, fmt.Errorf("block not found for block number (%d): %v", blockNr, err)
- }
-
- needReplay, err := api.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 := api.replay(ctx, block, accounts)
- return result, err
-}
-
-func (api *BlockChainAPI) GetVerifyResult(ctx context.Context, blockNr rpc.BlockNumber, blockHash common.Hash, diffHash common.Hash) *core.VerifyResult {
- return api.b.Chain().GetVerifyResult(uint64(blockNr), blockHash, diffHash)
-}
-
// RPCMarshalHeader converts the given header to the RPC output .
func RPCMarshalHeader(head *types.Header) map[string]interface{} {
result := map[string]interface{}{
diff --git a/node/node.go b/node/node.go
index 7fa1fd9aea..3426e1a4b7 100644
--- a/node/node.go
+++ b/node/node.go
@@ -36,7 +36,6 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/ethdb/leveldb"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
@@ -76,12 +75,11 @@ const (
initializingState = iota
runningState
closedState
- blockDbCacheSize = 256
- blockDbHandlesMinSize = 1000
- blockDbHandlesMaxSize = 2000
- chainDbMemoryPercentage = 50
- chainDbHandlesPercentage = 50
- diffStoreHandlesPercentage = 20
+ blockDbCacheSize = 256
+ blockDbHandlesMinSize = 1000
+ blockDbHandlesMaxSize = 2000
+ chainDbMemoryPercentage = 50
+ chainDbHandlesPercentage = 50
)
const StateDBNamespace = "eth/db/statedata/"
@@ -782,15 +780,11 @@ func (n *Node) OpenAndMergeDatabase(name string, namespace string, readonly bool
blockDb ethdb.Database
disableChainDbFreeze = false
blockDbHandlesSize int
- diffStoreHandles int
chainDataHandles = config.DatabaseHandles
chainDbCache = config.DatabaseCache
stateDbCache, stateDbHandles int
)
- if config.PersistDiff {
- diffStoreHandles = config.DatabaseHandles * diffStoreHandlesPercentage / 100
- }
isMultiDatabase := n.CheckIfMultiDataBase()
// Open the separated state database if the state directory exists
if isMultiDatabase {
@@ -831,15 +825,6 @@ func (n *Node) OpenAndMergeDatabase(name string, namespace string, readonly bool
chainDB.SetBlockStore(blockDb)
}
- if config.PersistDiff {
- diffStore, err := n.OpenDiffDatabase(name, diffStoreHandles, config.DatabaseDiff, namespace, readonly)
- if err != nil {
- chainDB.Close()
- return nil, err
- }
- chainDB.SetDiffStore(diffStore)
- }
-
return chainDB, nil
}
@@ -905,30 +890,6 @@ func (n *Node) CheckIfMultiDataBase() bool {
}
}
-func (n *Node) OpenDiffDatabase(name string, handles int, diff, namespace string, readonly bool) (*leveldb.Database, error) {
- n.lock.Lock()
- defer n.lock.Unlock()
- if n.state == closedState {
- return nil, ErrNodeStopped
- }
-
- var db *leveldb.Database
- var err error
- if n.config.DataDir == "" {
- panic("datadir is missing")
- }
- root := n.ResolvePath(name)
- switch {
- case diff == "":
- diff = filepath.Join(root, "diff")
- case !filepath.IsAbs(diff):
- diff = n.ResolvePath(diff)
- }
- db, err = leveldb.New(diff, 0, handles, namespace, readonly)
-
- return db, err
-}
-
// ResolvePath returns the absolute path of a resource in the instance directory.
func (n *Node) ResolvePath(x string) string {
return n.config.ResolvePath(x)
diff --git a/p2p/config.go b/p2p/config.go
index 7b5945fed6..c6f1bd5665 100644
--- a/p2p/config.go
+++ b/p2p/config.go
@@ -80,10 +80,6 @@ type Config struct {
// maintained and re-connected on disconnects.
StaticNodes []*enode.Node
- // Verify nodes are used as pre-configured connections which are always
- // maintained and re-connected on disconnects.
- VerifyNodes []*enode.Node
-
// Trusted nodes are used as pre-configured connections which are always
// allowed to connect, even above the peer limit.
TrustedNodes []*enode.Node
diff --git a/p2p/config_toml.go b/p2p/config_toml.go
index 805dc67b74..285ce53e45 100644
--- a/p2p/config_toml.go
+++ b/p2p/config_toml.go
@@ -29,7 +29,6 @@ func (c Config) MarshalTOML() (interface{}, error) {
BootstrapNodes []*enode.Node
BootstrapNodesV5 []*enode.Node `toml:",omitempty"`
StaticNodes []*enode.Node
- VerifyNodes []*enode.Node
TrustedNodes []*enode.Node
EVNNodeIdsWhitelist []enode.ID `toml:",omitempty"`
ProxyedValidatorAddresses []common.Address `toml:",omitempty"`
@@ -58,7 +57,6 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.BootstrapNodes = c.BootstrapNodes
enc.BootstrapNodesV5 = c.BootstrapNodesV5
enc.StaticNodes = c.StaticNodes
- enc.VerifyNodes = c.VerifyNodes
enc.TrustedNodes = c.TrustedNodes
enc.EVNNodeIdsWhitelist = c.EVNNodeIdsWhitelist
enc.ProxyedValidatorAddresses = c.ProxyedValidatorAddresses
@@ -91,7 +89,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
BootstrapNodes []*enode.Node
BootstrapNodesV5 []*enode.Node `toml:",omitempty"`
StaticNodes []*enode.Node
- VerifyNodes []*enode.Node
TrustedNodes []*enode.Node
EVNNodeIdsWhitelist []enode.ID `toml:",omitempty"`
ProxyedValidatorAddresses []common.Address `toml:",omitempty"`
@@ -147,9 +144,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.StaticNodes != nil {
c.StaticNodes = dec.StaticNodes
}
- if dec.VerifyNodes != nil {
- c.VerifyNodes = dec.VerifyNodes
- }
if dec.TrustedNodes != nil {
c.TrustedNodes = dec.TrustedNodes
}
diff --git a/p2p/peer.go b/p2p/peer.go
index 8f9ba8e2bc..3992102878 100644
--- a/p2p/peer.go
+++ b/p2p/peer.go
@@ -263,11 +263,6 @@ func (p *Peer) Inbound() bool {
return p.rw.is(inboundConn)
}
-// VerifyNode returns true if the peer is a verification connection
-func (p *Peer) VerifyNode() bool {
- return p.rw.is(verifyConn)
-}
-
func newPeer(log log.Logger, conn *conn, protocols []Protocol) *Peer {
protomap := matchProtocols(protocols, conn.caps, conn)
p := &Peer{
diff --git a/p2p/server.go b/p2p/server.go
index 48696a64c2..5533551824 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -142,7 +142,6 @@ const (
staticDialedConn
inboundConn
trustedConn
- verifyConn
)
// conn wraps a network connection with information gathered
@@ -194,9 +193,6 @@ func (f connFlag) String() string {
if f&inboundConn != 0 {
s += "-inbound"
}
- if f&verifyConn != 0 {
- s += "-verify"
- }
if s != "" {
s = s[1:]
}
@@ -587,9 +583,6 @@ func (srv *Server) setupDialScheduler() {
for _, n := range srv.StaticNodes {
srv.dialsched.addStatic(n)
}
- for _, n := range srv.VerifyNodes {
- srv.dialsched.addStatic(n)
- }
}
func (srv *Server) maxInboundConns() int {
@@ -602,7 +595,7 @@ func (srv *Server) SetFilter(f forkid.Filter) {
func (srv *Server) maxDialedConns() (limit int) {
if srv.NoDial {
- return len(srv.StaticNodes) + len(srv.VerifyNodes)
+ return len(srv.StaticNodes)
}
if srv.MaxPeers == 0 {
return 0
@@ -938,13 +931,6 @@ func (srv *Server) checkInboundConn(remoteIP netip.Addr) error {
// as a peer. It returns when the connection has been added as a peer
// or the handshakes have failed.
func (srv *Server) SetupConn(fd net.Conn, flags connFlag, dialDest *enode.Node) error {
- // If dialDest is verify node, set verifyConn flags.
- for _, n := range srv.VerifyNodes {
- if dialDest.ID() == n.ID() {
- flags |= verifyConn
- }
- }
-
c := &conn{fd: fd, flags: flags, cont: make(chan error)}
if dialDest == nil {
c.transport = srv.newTransport(fd, nil)
diff --git a/tests/state_test_util.go b/tests/state_test_util.go
index 0da6efa13b..4fb1caddb3 100644
--- a/tests/state_test_util.go
+++ b/tests/state_test_util.go
@@ -349,7 +349,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
// Commit state mutations into database.
st.StateDB.SetExpectedStateRoot(root)
- root, _, _ = st.StateDB.Commit(block.NumberU64(), config.IsEIP158(block.Number()), config.IsCancun(block.Number(), block.Time()))
+ root, _ = st.StateDB.Commit(block.NumberU64(), config.IsEIP158(block.Number()), config.IsCancun(block.Number(), block.Time()))
if tracer := evm.Config.Tracer; tracer != nil && tracer.OnTxEnd != nil {
receipt := &types.Receipt{GasUsed: vmRet.UsedGas}
tracer.OnTxEnd(receipt, nil)
@@ -525,7 +525,7 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc, snapshotter bo
// Commit and re-open to start with a clean state.
root := statedb.IntermediateRoot(false)
statedb.SetExpectedStateRoot(root)
- root, _, _ = statedb.Commit(0, false, false)
+ root, _ = statedb.Commit(0, false, false)
// If snapshot is requested, initialize the snapshotter and use it in state.
var snaps *snapshot.Tree