From 529e66eb795001754335f305edd86477d5daefdf Mon Sep 17 00:00:00 2001 From: Keefe-Liu Date: Tue, 25 Jan 2022 21:18:56 +0800 Subject: [PATCH] fix misc bugs of verify node --- cmd/utils/flags.go | 3 +- common/types.go | 15 ----- core/blockchain.go | 106 +++++++++++++++++++-------------- core/blockchain_diff_test.go | 14 ++--- core/state_processor.go | 2 +- core/types/block.go | 62 ++----------------- eth/backend.go | 18 ++++-- eth/ethconfig/config.go | 5 +- eth/ethconfig/gen_config.go | 6 ++ eth/peerset.go | 3 + eth/protocols/diff/protocol.go | 2 +- eth/protocols/trust/handler.go | 6 +- internal/ethapi/api.go | 2 +- 13 files changed, 105 insertions(+), 139 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index fbca81a15d..a407098e61 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1712,7 +1712,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { cfg.RPCTxFeeCap = ctx.GlobalFloat64(RPCGlobalTxFeeCapFlag.Name) } if ctx.GlobalIsSet(NoDiscoverFlag.Name) { - cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs = []string{}, []string{} + cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs, cfg.TrustDiscoveryURLs = []string{}, []string{}, []string{} } else if ctx.GlobalIsSet(DNSDiscoveryFlag.Name) { urls := ctx.GlobalString(DNSDiscoveryFlag.Name) if urls == "" { @@ -1818,6 +1818,7 @@ 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 } } diff --git a/common/types.go b/common/types.go index 15f2bce681..d715356692 100644 --- a/common/types.go +++ b/common/types.go @@ -354,21 +354,6 @@ func (a *Address) UnmarshalGraphQL(input interface{}) error { return err } -// AddressSlice is used for sort -type AddressSlice []Address - -func (s AddressSlice) Len() int { - return len(s) -} - -func (s AddressSlice) Less(i, j int) bool { - return s[i].Hex() < s[j].Hex() -} - -func (s AddressSlice) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} - // UnprefixedAddress allows marshaling an Address without 0x prefix. type UnprefixedAddress Address diff --git a/core/blockchain.go b/core/blockchain.go index 78b88b5b1e..6e1a174dbb 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -501,7 +501,22 @@ func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts) { bc.receiptsCache.Add(hash, receipts) } -func (bc *BlockChain) cacheDiffLayer(diffLayer *types.DiffLayer) { +func (bc *BlockChain) cacheDiffLayer(diffLayer *types.DiffLayer, sorted bool) { + if !sorted { + 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() + }) + } + if bc.diffLayerCache.Len() >= diffLayerCacheLimit { bc.diffLayerCache.RemoveOldest() } @@ -1801,12 +1816,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. diffLayer.BlockHash = block.Hash() diffLayer.Number = block.NumberU64() - sort.Sort(types.DiffCodeSlice(diffLayer.Codes)) - sort.Sort(common.AddressSlice(diffLayer.Destructs)) - sort.Sort(types.DiffAccountSlice(diffLayer.Accounts)) - sort.Sort(types.DiffStorageSlice(diffLayer.Storages)) - - bc.cacheDiffLayer(diffLayer) + go bc.cacheDiffLayer(diffLayer, false) } wg.Wait() @@ -2798,9 +2808,14 @@ func (bc *BlockChain) HandleDiffLayer(diffLayer *types.DiffLayer, pid string, fu return nil } + diffHash := common.Hash{} + if diffLayer.DiffHash.Load() != nil { + diffHash = diffLayer.DiffHash.Load().(common.Hash) + } + bc.diffMux.Lock() defer bc.diffMux.Unlock() - if blockHash, exist := bc.diffHashToBlockHash[diffLayer.DiffHash]; exist && blockHash == diffLayer.BlockHash { + if blockHash, exist := bc.diffHashToBlockHash[diffHash]; exist && blockHash == diffLayer.BlockHash { return nil } @@ -2814,28 +2829,28 @@ func (bc *BlockChain) HandleDiffLayer(diffLayer *types.DiffLayer, pid string, fu return nil } if _, exist := bc.diffPeersToDiffHashes[pid]; exist { - if _, alreadyHas := bc.diffPeersToDiffHashes[pid][diffLayer.DiffHash]; alreadyHas { + if _, alreadyHas := bc.diffPeersToDiffHashes[pid][diffHash]; alreadyHas { return nil } } else { bc.diffPeersToDiffHashes[pid] = make(map[common.Hash]struct{}) } - bc.diffPeersToDiffHashes[pid][diffLayer.DiffHash] = struct{}{} + bc.diffPeersToDiffHashes[pid][diffHash] = struct{}{} if _, exist := bc.diffNumToBlockHashes[diffLayer.Number]; !exist { bc.diffNumToBlockHashes[diffLayer.Number] = make(map[common.Hash]struct{}) } bc.diffNumToBlockHashes[diffLayer.Number][diffLayer.BlockHash] = struct{}{} - if _, exist := bc.diffHashToPeers[diffLayer.DiffHash]; !exist { - bc.diffHashToPeers[diffLayer.DiffHash] = make(map[string]struct{}) + if _, exist := bc.diffHashToPeers[diffHash]; !exist { + bc.diffHashToPeers[diffHash] = make(map[string]struct{}) } - bc.diffHashToPeers[diffLayer.DiffHash][pid] = struct{}{} + bc.diffHashToPeers[diffHash][pid] = struct{}{} if _, exist := bc.blockHashToDiffLayers[diffLayer.BlockHash]; !exist { bc.blockHashToDiffLayers[diffLayer.BlockHash] = make(map[common.Hash]*types.DiffLayer) } - bc.blockHashToDiffLayers[diffLayer.BlockHash][diffLayer.DiffHash] = diffLayer - bc.diffHashToBlockHash[diffLayer.DiffHash] = diffLayer.BlockHash + bc.blockHashToDiffLayers[diffLayer.BlockHash][diffHash] = diffLayer + bc.diffHashToBlockHash[diffHash] = diffLayer.BlockHash return nil } @@ -3120,60 +3135,55 @@ func EnablePersistDiff(limit uint64) BlockChainOption { } } -func (bc *BlockChain) GetRootByDiffHash(blockNumber uint64, blockHash common.Hash, diffHash common.Hash) (*types.VerifyResult, error) { +func (bc *BlockChain) GetRootByDiffHash(blockNumber uint64, blockHash common.Hash, diffHash common.Hash) *types.VerifyResult { var res types.VerifyResult res.BlockNumber = blockNumber res.BlockHash = blockHash - if blockNumber > bc.CurrentHeader().Number.Uint64()+11 { + if blockNumber > bc.CurrentHeader().Number.Uint64()+maxDiffForkDist { res.Status = types.StatusBlockTooNew - return &res, nil + return &res } else if blockNumber > bc.CurrentHeader().Number.Uint64() { res.Status = types.StatusBlockNewer - return &res, nil + 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 == (common.Hash{}) { - hash, err := GetTrustedDiffHash(diff) + if diff.DiffHash.Load() == nil { + hash, err := CalculateDiffHash(diff) if err != nil { res.Status = types.StatusUnexpectedError - return &res, err + return &res } - diff.DiffHash = hash + diff.DiffHash.Store(hash) } - if diffHash != diff.DiffHash { + if diffHash != diff.DiffHash.Load().(common.Hash) { res.Status = types.StatusDiffHashMismatch - return &res, nil + return &res } - header := bc.GetHeaderByHash(blockHash) - if header == nil { - res.Status = types.StatusUnexpectedError - return &res, fmt.Errorf("unexpected error, header not found") - } res.Status = types.StatusFullVerified res.Root = header.Root - return &res, nil - } - - header := bc.GetHeaderByHash(blockHash) - if header == nil { - if blockNumber > bc.CurrentHeader().Number.Uint64()-11 { - res.Status = types.StatusPossibleFork - return &res, nil - } - - res.Status = types.StatusImpossibleFork - return &res, nil + return &res } - res.Status = types.StatusUntrustedVerified + res.Status = types.StatusPartiallyVerified res.Root = header.Root - return &res, nil + return &res } func (bc *BlockChain) GetTrustedDiffLayer(blockHash common.Hash) *types.DiffLayer { @@ -3245,12 +3255,18 @@ func (bc *BlockChain) GenerateDiffLayer(blockHash common.Hash) (*types.DiffLayer if diffLayer != nil { diffLayer.BlockHash = blockHash diffLayer.Number = block.NumberU64() + + bc.cacheDiffLayer(diffLayer, true) } return diffLayer, nil } -func GetTrustedDiffHash(d *types.DiffLayer) (common.Hash, error) { +func CalculateDiffHash(d *types.DiffLayer) (common.Hash, error) { + if d == nil { + return common.Hash{}, fmt.Errorf("nil diff layer") + } + diff := &types.ExtDiffLayer{ BlockHash: d.BlockHash, Receipts: make([]*types.ReceiptForStorage, 0), diff --git a/core/blockchain_diff_test.go b/core/blockchain_diff_test.go index 1c749be72c..ab5af2815c 100644 --- a/core/blockchain_diff_test.go +++ b/core/blockchain_diff_test.go @@ -288,7 +288,7 @@ func rawDataToDiffLayer(data rlp.RawValue) (*types.DiffLayer, error) { hasher.Write(data) var diffHash common.Hash hasher.Sum(diffHash[:0]) - diff.DiffHash = diffHash + diff.DiffHash.Store(diffHash) hasher.Reset() return &diff, nil } @@ -600,13 +600,13 @@ func testGetRootByDiffHash(t *testing.T, chain1, chain2 *BlockChain, blockNumber diffHash2 := types.EmptyRootHash if status != types.StatusDiffHashMismatch { var err error - diffHash2, err = GetTrustedDiffHash(diffLayer2) + diffHash2, err = CalculateDiffHash(diffLayer2) if err != nil { t.Fatalf("failed to compute diff hash: %v", err) } } - if status == types.StatusUntrustedVerified { + if status == types.StatusPartiallyVerified { block1 := chain1.GetBlockByNumber(blockNumber) if block1 == nil { t.Fatalf("failed to find block, number: %v", blockNumber) @@ -614,7 +614,7 @@ func testGetRootByDiffHash(t *testing.T, chain1, chain2 *BlockChain, blockNumber chain1.diffLayerCache.Remove(block1.Hash()) } - result, _ := chain1.GetRootByDiffHash(blockNumber, block2.Hash(), diffHash2) + result := chain1.GetRootByDiffHash(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) } @@ -639,7 +639,7 @@ func TestGetRootByDiffHash(t *testing.T) { } testGetRootByDiffHash(t, chain1, chain2, 10, types.StatusFullVerified) - testGetRootByDiffHash(t, chain1, chain2, 2, types.StatusUntrustedVerified) + 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) @@ -743,7 +743,7 @@ func TestGenerateDiffLayer(t *testing.T) { } t.Fatalf("unexpected nil diff layer, block number: %v, block hash: %v", blockNr, block.Hash()) } - expDiffHash, err := GetTrustedDiffHash(expDiffLayer) + expDiffHash, err := CalculateDiffHash(expDiffLayer) if err != nil { t.Fatalf("compute diff hash failed: %v", err) } @@ -752,7 +752,7 @@ func TestGenerateDiffLayer(t *testing.T) { if err != nil || diffLayer == nil { t.Fatalf("generate diff layer failed: %v", err) } - diffHash, err := GetTrustedDiffHash(diffLayer) + diffHash, err := CalculateDiffHash(diffLayer) if err != nil { t.Fatalf("compute diff hash failed: %v", err) } diff --git a/core/state_processor.go b/core/state_processor.go index a21d68c504..16f6eab63b 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -118,7 +118,7 @@ func (p *LightStateProcessor) Process(block *types.Block, statedb *state.StateDB return statedb, receipts, logs, gasUsed, nil } log.Error("do light process err at block", "num", block.NumberU64(), "err", err) - p.bc.removeDiffLayers(diffLayer.DiffHash) + p.bc.removeDiffLayers(diffLayer.DiffHash.Load().(common.Hash)) // prepare new statedb statedb.StopPrefetcher() parent := p.bc.GetHeader(block.ParentHash(), block.NumberU64()-1) diff --git a/core/types/block.go b/core/types/block.go index f3c487b684..72cf3408b5 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -49,7 +49,7 @@ var ( // StatusVerified means the processing of request going as expected and found the root correctly. StatusVerified = VerifyStatus{Code: 0x100} StatusFullVerified = VerifyStatus{Code: 0x101, Msg: "state root full verified"} - StatusUntrustedVerified = VerifyStatus{Code: 0x102, Msg: "state root untrusted verified, because of difflayer not found"} + StatusPartiallyVerified = VerifyStatus{Code: 0x102, Msg: "state root partially verified, because of difflayer not found"} // StatusFailed means the request has something wrong. StatusFailed = VerifyStatus{Code: 0x200} @@ -57,11 +57,10 @@ var ( StatusImpossibleFork = VerifyStatus{Code: 0x202, Msg: "verify failed because of impossible fork detected"} // StatusUncertain means verify node can't give a certain result of the request. - StatusUncertain = VerifyStatus{Code: 0x300} - StatusBlockTooNew = VerifyStatus{Code: 0x301, Msg: "can’t verify because of block number larger than current height more than 11"} - StatusBlockNewer = VerifyStatus{Code: 0x302, Msg: "can’t verify because of block number larger than current height"} - StatusPossibleFork = VerifyStatus{Code: 0x303, Msg: "can’t verify because of possible fork detected"} - StatusRequestTooBusy = VerifyStatus{Code: 0x304, Msg: "can’t verify because of request too busy"} + StatusUncertain = VerifyStatus{Code: 0x300} + StatusBlockTooNew = VerifyStatus{Code: 0x301, Msg: "can’t verify because of block number larger than current height more than 11"} + StatusBlockNewer = VerifyStatus{Code: 0x302, Msg: "can’t verify because of block number larger than current height"} + StatusPossibleFork = VerifyStatus{Code: 0x303, Msg: "can’t verify because of possible fork detected"} // StatusUnexpectedError is unexpected internal error. StatusUnexpectedError = VerifyStatus{Code: 0x400, Msg: "can’t verify because of unexpected internal error"} @@ -414,7 +413,7 @@ type DiffLayer struct { Accounts []DiffAccount Storages []DiffStorage - DiffHash common.Hash + DiffHash atomic.Value } type ExtDiffLayer struct { @@ -477,66 +476,17 @@ type DiffCode struct { Code []byte } -// DiffCodeSlice is used for sort -type DiffCodeSlice []DiffCode - -func (s DiffCodeSlice) Len() int { - return len(s) -} - -func (s DiffCodeSlice) Less(i, j int) bool { - return s[i].Hash.Hex() < s[j].Hash.Hex() -} - -func (s DiffCodeSlice) Swap(i, j int) { - s[i].Hash, s[j].Hash = s[j].Hash, s[i].Hash - s[i].Code, s[j].Code = s[j].Code, s[i].Code -} - type DiffAccount struct { Account common.Address Blob []byte } -// DiffAccountSlice is used for sort -type DiffAccountSlice []DiffAccount - -func (s DiffAccountSlice) Len() int { - return len(s) -} - -func (s DiffAccountSlice) Less(i, j int) bool { - return s[i].Account.Hex() < s[j].Account.Hex() -} - -func (s DiffAccountSlice) Swap(i, j int) { - s[i].Account, s[j].Account = s[j].Account, s[i].Account - s[i].Blob, s[j].Blob = s[j].Blob, s[i].Blob -} - type DiffStorage struct { Account common.Address Keys []string Vals [][]byte } -// DiffStorageSlice is used for sort -type DiffStorageSlice []DiffStorage - -func (s DiffStorageSlice) Len() int { - return len(s) -} - -func (s DiffStorageSlice) Less(i, j int) bool { - return s[i].Account.Hex() < s[j].Account.Hex() -} - -func (s DiffStorageSlice) Swap(i, j int) { - s[i].Account, s[j].Account = s[j].Account, s[i].Account - s[i].Keys, s[j].Keys = s[j].Keys, s[i].Keys - s[i].Vals, s[j].Vals = s[j].Vals, s[i].Vals -} - type DiffAccountsInTx struct { TxHash common.Hash Accounts map[common.Address]*big.Int diff --git a/eth/backend.go b/eth/backend.go index b9e8e40cb9..0e937c49a0 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -70,11 +70,12 @@ type Ethereum struct { config *ethconfig.Config // Handlers - txPool *core.TxPool - blockchain *core.BlockChain - handler *handler - ethDialCandidates enode.Iterator - snapDialCandidates enode.Iterator + txPool *core.TxPool + blockchain *core.BlockChain + handler *handler + ethDialCandidates enode.Iterator + snapDialCandidates enode.Iterator + trustDialCandidates enode.Iterator // DB interfaces chainDb ethdb.Database // Block chain database @@ -272,6 +273,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { if err != nil { return nil, err } + eth.trustDialCandidates, err = dnsclient.NewIterator(eth.config.TrustDiscoveryURLs...) + if err != nil { + return nil, err + } // Start the RPC service eth.netRPCService = ethapi.NewPublicNetAPI(eth.p2pServer, config.NetworkId) @@ -556,7 +561,7 @@ func (s *Ethereum) Protocols() []p2p.Protocol { } // diff protocol can still open without snap protocol protos = append(protos, diff.MakeProtocols((*diffHandler)(s.handler), s.snapDialCandidates)...) - protos = append(protos, trust.MakeProtocols((*trustHandler)(s.handler), s.snapDialCandidates)...) + protos = append(protos, trust.MakeProtocols((*trustHandler)(s.handler), s.trustDialCandidates)...) return protos } @@ -587,6 +592,7 @@ func (s *Ethereum) Stop() error { // Stop all the peer-related stuff first. s.ethDialCandidates.Close() s.snapDialCandidates.Close() + s.trustDialCandidates.Close() s.handler.Stop() // Then stop everything else. diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 4f2c87c52e..ee35d123a3 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -131,8 +131,9 @@ type Config struct { // This can be set to list of enrtree:// URLs which will be queried for // for nodes to connect to. - EthDiscoveryURLs []string - SnapDiscoveryURLs []string + EthDiscoveryURLs []string + SnapDiscoveryURLs []string + TrustDiscoveryURLs []string NoPruning bool // Whether to disable pruning and flush everything to disk DirectBroadcast bool diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index ba2996279d..c5e46ced41 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -24,6 +24,7 @@ func (c Config) MarshalTOML() (interface{}, error) { DisablePeerTxBroadcast bool EthDiscoveryURLs []string SnapDiscoveryURLs []string + TrustDiscoveryURLs []string NoPruning bool NoPrefetch bool DirectBroadcast bool @@ -79,6 +80,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.DisablePeerTxBroadcast = c.DisablePeerTxBroadcast enc.EthDiscoveryURLs = c.EthDiscoveryURLs enc.SnapDiscoveryURLs = c.SnapDiscoveryURLs + enc.TrustDiscoveryURLs = c.TrustDiscoveryURLs enc.NoPruning = c.NoPruning enc.DirectBroadcast = c.DirectBroadcast enc.DisableSnapProtocol = c.DisableSnapProtocol @@ -137,6 +139,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { DisablePeerTxBroadcast *bool EthDiscoveryURLs []string SnapDiscoveryURLs []string + TrustDiscoveryURLs []string NoPruning *bool NoPrefetch *bool DirectBroadcast *bool @@ -207,6 +210,9 @@ 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.NoPruning != nil { c.NoPruning = *dec.NoPruning } diff --git a/eth/peerset.go b/eth/peerset.go index dc1d7da45e..5bbaa2dd2b 100644 --- a/eth/peerset.go +++ b/eth/peerset.go @@ -335,6 +335,9 @@ func (ps *peerSet) GetDiffPeer(pid string) downloader.IDiffPeer { // GetVerifyPeers returns an array of verify nodes. func (ps *peerSet) GetVerifyPeers() []*trustPeer { + ps.lock.RLock() + defer ps.lock.RUnlock() + res := make([]*trustPeer, 0) for _, p := range ps.peers { if p.trustExt != nil { diff --git a/eth/protocols/diff/protocol.go b/eth/protocols/diff/protocol.go index 4467d0b327..e6bf5b3e14 100644 --- a/eth/protocols/diff/protocol.go +++ b/eth/protocols/diff/protocol.go @@ -92,7 +92,7 @@ func (p *DiffLayersPacket) Unpack() ([]*types.DiffLayer, error) { var diffHash common.Hash hasher.Sum(diffHash[:0]) hasher.Reset() - diff.DiffHash = diffHash + diff.DiffHash.Store(diffHash) } return diffLayers, nil } diff --git a/eth/protocols/trust/handler.go b/eth/protocols/trust/handler.go index ce8fc4cd8d..9b93d4a228 100644 --- a/eth/protocols/trust/handler.go +++ b/eth/protocols/trust/handler.go @@ -126,8 +126,8 @@ func handleRootRequest(backend Backend, msg Decoder, peer *Peer) error { return fmt.Errorf("%w: message %v: %v", errDecode, msg, err) } - res, err := backend.Chain().GetRootByDiffHash(req.BlockNumber, req.BlockHash, req.DiffHash) - p2p.Send(peer.rw, RespondRootMsg, RootResponsePacket{ + res := backend.Chain().GetRootByDiffHash(req.BlockNumber, req.BlockHash, req.DiffHash) + return p2p.Send(peer.rw, RespondRootMsg, RootResponsePacket{ RequestId: req.RequestId, Status: res.Status, BlockNumber: req.BlockNumber, @@ -135,8 +135,6 @@ func handleRootRequest(backend Backend, msg Decoder, peer *Peer) error { Root: res.Root, Extra: defaultExtra, }) - - return err } func handleRootResponse(backend Backend, msg Decoder, peer *Peer) error { diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index b01ec8b2e5..f3bcc3b98d 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1287,7 +1287,7 @@ func (s *PublicBlockChainAPI) GetDiffAccountsWithScope(ctx context.Context, bloc return result, err } -func (s *PublicBlockChainAPI) GetRootByDiffHash(ctx context.Context, blockNr rpc.BlockNumber, blockHash common.Hash, diffHash common.Hash) (*types.VerifyResult, error) { +func (s *PublicBlockChainAPI) GetRootByDiffHash(ctx context.Context, blockNr rpc.BlockNumber, blockHash common.Hash, diffHash common.Hash) *types.VerifyResult { return s.b.Chain().GetRootByDiffHash(uint64(blockNr), blockHash, diffHash) }