From a338bd1a59550c32324e70ee6c7b184e82c746de Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Thu, 15 Dec 2022 15:13:14 +0530 Subject: [PATCH] Avoid EOAs in additional data in response --- pkg/eth/backend.go | 13 +++++-------- pkg/eth/eth_state_test.go | 23 ----------------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/pkg/eth/backend.go b/pkg/eth/backend.go index fa1f8fb7..439743b5 100644 --- a/pkg/eth/backend.go +++ b/pkg/eth/backend.go @@ -984,20 +984,17 @@ func (b *Backend) GetStateSlice(path string, depth int, root common.Hash) (*GetS leafNodes = append(leafNodes, sliceLeafCIDs...) leafNodes = append(leafNodes, headLeafCID...) - contractCount := 0 for _, leafNodeCID := range leafNodes { stateLeafKey, storageRoot, code, err := b.getAccountByStateCID(tx, leafNodeCID.String(), blockHeight) if err != nil { return nil, fmt.Errorf("GetStateSlice account lookup error: %s", err.Error()) } - response.Leaves[stateLeafKey] = GetSliceResponseAccount{ - StorageRoot: storageRoot, - EVMCode: common.Bytes2Hex(code), - } - if len(code) > 0 { - contractCount++ + response.Leaves[stateLeafKey] = GetSliceResponseAccount{ + StorageRoot: storageRoot, + EVMCode: common.Bytes2Hex(code), + } } } @@ -1011,7 +1008,7 @@ func (b *Backend) GetStateSlice(path string, depth int, root common.Hash) (*GetS response.MetaData.NodeStats["02-total-trie-nodes"] = strconv.Itoa(len(response.TrieNodes.Stem) + len(response.TrieNodes.Head) + len(response.TrieNodes.Slice)) response.MetaData.NodeStats["03-leaves"] = strconv.Itoa(len(leafNodes)) - response.MetaData.NodeStats["04-smart-contracts"] = strconv.Itoa(contractCount) + response.MetaData.NodeStats["04-smart-contracts"] = strconv.Itoa(len(response.Leaves)) response.MetaData.NodeStats["00-stem-and-head-nodes"] = strconv.Itoa(len(response.TrieNodes.Stem) + len(response.TrieNodes.Head)) return response, nil diff --git a/pkg/eth/eth_state_test.go b/pkg/eth/eth_state_test.go index d3cb664a..32d78d24 100644 --- a/pkg/eth/eth_state_test.go +++ b/pkg/eth/eth_state_test.go @@ -59,19 +59,12 @@ var ( account1Code = "608060405234801561001057600080fd5b50600436106100415760003560e01c806343d726d61461004657806365f3c31a1461005057806373d4a13a1461007e575b600080fd5b61004e61009c565b005b61007c6004803603602081101561006657600080fd5b810190808035906020019092919050505061017b565b005b610086610185565b6040518082815260200191505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610141576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061018c6022913960400191505060405180910390fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b8060018190555050565b6001548156fe4f6e6c79206f776e65722063616e2063616c6c20746869732066756e6374696f6e2ea265627a7a723158205ba91466129f45285f53176d805117208c231ec6343d7896790e6fc4165b802b64736f6c63430005110032" account2DataHash = "2d264f591aa3fa9df3cbeea190a4fd8d5483ddfb1b85603b2a006d179f79ba35" account2Data = "f871a03926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2b84ef84c02881bc16d674ec82710a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" - account2StateLeafKey = "0xe926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2" account3DataHash = "408dd81f6cd5c614f91ecd9faa01d5feba936e0314ba04f99c74069ba819e0f2" account3Data = "f86da030bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2ab84af848058405f5b608a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" - account3StateLeafKey = "0x00bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a" account4DataHash = "422c7cc4fa407603f0879a0ecaa809682ce98dbef30551a34bcce09fa3ac9951" account4Data = "f871a03957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45b84ef84c80883782dace9d9003e8a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" - account4StateLeafKey = "0xc957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45" account5DataHash = "b356351d60bc9894cf1f1d6cb68c815f0131d50f1da83c4023a09ec855cfff91" account5Data = "f871a03380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312ab84ef84c80883782dace9d900000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" - account5StateLeafKey = "0x5380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a" - - emptyStorageRoot = common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") - emptyCode = "" contractStorageRootBlock5 = common.HexToHash("0x4bd45c41d863f1bcf5da53364387fcdd64f77924d388a4df47e64132273fb4c0") storageRootDataHashBlock5 = "4bd45c41d863f1bcf5da53364387fcdd64f77924d388a4df47e64132273fb4c0" @@ -607,22 +600,6 @@ var _ = Describe("eth state reading tests", func() { StorageRoot: contractStorageRootBlock5.Hex(), EVMCode: account1Code, }, - account2StateLeafKey: { - StorageRoot: emptyStorageRoot.Hex(), - EVMCode: emptyCode, - }, - account3StateLeafKey: { - StorageRoot: emptyStorageRoot.Hex(), - EVMCode: emptyCode, - }, - account4StateLeafKey: { - StorageRoot: emptyStorageRoot.Hex(), - EVMCode: emptyCode, - }, - account5StateLeafKey: { - StorageRoot: emptyStorageRoot.Hex(), - EVMCode: emptyCode, - }, }, }