From 5a2557c4735a311fec6c70703d976f50a33125bf Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 29 May 2024 18:12:00 +0800 Subject: [PATCH 1/2] rm unused --- trie_by_cid/helper/hasher.go | 38 ----------------- trie_by_cid/helper/statediff_helper.go | 58 -------------------------- 2 files changed, 96 deletions(-) delete mode 100644 trie_by_cid/helper/hasher.go delete mode 100644 trie_by_cid/helper/statediff_helper.go diff --git a/trie_by_cid/helper/hasher.go b/trie_by_cid/helper/hasher.go deleted file mode 100644 index feb5511..0000000 --- a/trie_by_cid/helper/hasher.go +++ /dev/null @@ -1,38 +0,0 @@ -package helper - -import ( - "hash" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "golang.org/x/crypto/sha3" -) - -var _ types.TrieHasher = &testHasher{} - -// testHasher (copied from go-ethereum/core/types/block_test.go) -// satisfies types.TrieHasher -type testHasher struct { - hasher hash.Hash -} - -func NewHasher() *testHasher { - return &testHasher{hasher: sha3.NewLegacyKeccak256()} -} - -func (h *testHasher) Reset() { - h.hasher.Reset() -} - -func (h *testHasher) Update(key, val []byte) error { - _, err := h.hasher.Write(key) - if err != nil { - return err - } - _, err = h.hasher.Write(val) - return err -} - -func (h *testHasher) Hash() common.Hash { - return common.BytesToHash(h.hasher.Sum(nil)) -} diff --git a/trie_by_cid/helper/statediff_helper.go b/trie_by_cid/helper/statediff_helper.go deleted file mode 100644 index 0f0820b..0000000 --- a/trie_by_cid/helper/statediff_helper.go +++ /dev/null @@ -1,58 +0,0 @@ -package helper - -import ( - "context" - "math/big" - - "github.com/cerc-io/plugeth-statediff" - "github.com/cerc-io/plugeth-statediff/adapt" - "github.com/cerc-io/plugeth-statediff/indexer" - "github.com/cerc-io/plugeth-statediff/indexer/database/sql/postgres" - "github.com/cerc-io/plugeth-statediff/indexer/node" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/state" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/params" -) - -var ( - ChainConfig = params.TestChainConfig - - mockTD = big.NewInt(1) -) - -// IndexStateDiff indexes a single statediff. -// - uses TestChainConfig -// - block hash/number are left as zero -func IndexStateDiff(dbConfig postgres.Config, stateCache state.Database, rootA, rootB common.Hash) error { - _, indexer, err := indexer.NewStateDiffIndexer( - context.Background(), ChainConfig, node.Info{}, dbConfig, true) - if err != nil { - return err - } - defer indexer.Close() // fixme: hangs when using PGX driver - - builder := statediff.NewBuilder(adapt.GethStateView(stateCache)) - block := types.NewBlock(&types.Header{Root: rootB}, nil, nil, nil, NewHasher()) - - // uses zero block hash/number, we only need the trie structure here - args := statediff.Args{ - OldStateRoot: rootA, - NewStateRoot: rootB, - } - diff, err := builder.BuildStateDiffObject(args, statediff.Params{}) - if err != nil { - return err - } - tx, err := indexer.PushBlock(block, nil, mockTD) - if err != nil { - return err - } - // we don't need to index diff.Nodes since we are just interested in the trie - for _, ipld := range diff.IPLDs { - if err := indexer.PushIPLD(tx, ipld); err != nil { - return err - } - } - return tx.Submit() -} -- 2.45.2 From 144b7365f41ec83b2d565e434155fdede245096e Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 29 May 2024 18:26:20 +0800 Subject: [PATCH 2/2] mod replace not needed --- go.mod | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 4678031..5ffa402 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/VictoriaMetrics/fastcache v1.12.2 github.com/cerc-io/ipfs-ethdb/v5 v5.1.0-alpha - github.com/cerc-io/plugeth-statediff v0.2.0 + github.com/cerc-io/plugeth-statediff v0.2.1 github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 github.com/davecgh/go-spew v1.1.1 github.com/ethereum/go-ethereum v1.13.14 @@ -111,8 +111,3 @@ require ( lukechampine.com/blake3 v1.2.2 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) - -replace ( - github.com/cerc-io/ipfs-ethdb/v5 => github.com/cerc-io/ipfs-ethdb/v5 v5.1.0-alpha - github.com/cerc-io/plugeth-statediff => github.com/cerc-io/plugeth-statediff v0.2.1 -) -- 2.45.2