Skip to content

Commit 5b63446

Browse files
Restructure statediff directory
1 parent 869a34c commit 5b63446

File tree

18 files changed

+128
-334
lines changed

18 files changed

+128
-334
lines changed

cmd/utils/flags.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import (
5858
"github.com/ethereum/go-ethereum/params"
5959
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
6060
"gopkg.in/urfave/cli.v1"
61-
"github.com/ethereum/go-ethereum/statediff"
61+
"github.com/ethereum/go-ethereum/statediff/service"
6262
)
6363

6464
var (
@@ -1334,7 +1334,7 @@ func RegisterStateDiffService(stack *node.Node) {
13341334
ctx.Service(&ethServ)
13351335
chainDb := ethServ.ChainDb()
13361336
blockChain := ethServ.BlockChain()
1337-
return statediff.NewStateDiffService(chainDb, blockChain)
1337+
return service.NewStateDiffService(chainDb, blockChain)
13381338
}); err != nil {
13391339
Fatalf("Failed to register State Diff Service", err)
13401340
}

statediff/builder.go renamed to statediff/builder/builder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Contains a batch of utility type declarations used by the tests. As the node
1818
// operates on unique types, a lot of them are needed to check various features.
1919

20-
package statediff
20+
package builder
2121

2222
import (
2323
"github.com/ethereum/go-ethereum/common"
@@ -50,7 +50,6 @@ func (sdb *builder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, block
5050
oldTrie, err := trie.New(oldStateRoot, sdb.trieDB)
5151
if err != nil {
5252
log.Debug("error creating oldTrie", err)
53-
//getting this error: error creating oldTrie missing trie node ddfbb83966d870891aa47147269447a83564d1defaefad5f9844a3a3a2a08433 (path )
5453
return nil, err
5554
}
5655
newTrie, err := trie.New(newStateRoot, sdb.trieDB)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package builder_test
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestBuilder(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "Builder Suite")
13+
}

statediff/builder_test.go renamed to statediff/builder/builder_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Contains a batch of utility type declarations used by the tests. As the node
1818
// operates on unique types, a lot of them are needed to check various features.
1919

20-
package statediff_test
20+
package builder_test
2121

2222
import (
2323
"github.com/onsi/ginkgo"
@@ -29,8 +29,8 @@ import (
2929
"github.com/ethereum/go-ethereum/consensus/ethash"
3030
"math/big"
3131
"github.com/ethereum/go-ethereum/crypto"
32-
"github.com/ethereum/go-ethereum/statediff"
3332
"github.com/onsi/gomega"
33+
b "github.com/ethereum/go-ethereum/statediff/builder"
3434
)
3535

3636

@@ -50,8 +50,8 @@ var (
5050
contractCode = common.Hex2Bytes("606060405260cc8060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146041578063c16431b914606b57603f565b005b6055600480803590602001909190505060a9565b6040518082815260200191505060405180910390f35b60886004808035906020019091908035906020019091905050608a565b005b80600060005083606481101560025790900160005b50819055505b5050565b6000600060005082606481101560025790900160005b5054905060c7565b91905056")
5151
contractAddr common.Address
5252

53-
emptyAccountDiffEventualMap = make(map[common.Address]statediff.AccountDiffEventual)
54-
emptyAccountDiffIncrementalMap = make(map[common.Address]statediff.AccountDiffIncremental)
53+
emptyAccountDiffEventualMap = make(map[common.Address]b.AccountDiffEventual)
54+
emptyAccountDiffIncrementalMap = make(map[common.Address]b.AccountDiffIncremental)
5555
)
5656
/*
5757
contract test {
@@ -121,10 +121,10 @@ var _ = ginkgo.FDescribe("", func() {
121121
var (
122122
block0Hash, block1Hash, block2Hash, block3Hash common.Hash
123123
block0, block1, block2, block3 *types.Block
124-
builder statediff.Builder
124+
builder b.Builder
125125
miningReward = int64(3000000000000000000)
126126
burnAddress = common.HexToAddress("0x0")
127-
diff *statediff.StateDiff
127+
diff *b.StateDiff
128128
err error
129129
)
130130

@@ -139,11 +139,11 @@ var _ = ginkgo.FDescribe("", func() {
139139
block1 = blocks[block1Hash]
140140
block2 = blocks[block2Hash]
141141
block3 = blocks[block3Hash]
142-
builder = statediff.NewBuilder(testdb)
142+
builder = b.NewBuilder(testdb)
143143
})
144144

145145
ginkgo.It("returns empty account diff collections when the state root hasn't changed", func() {
146-
expectedDiff := statediff.StateDiff{
146+
expectedDiff := b.StateDiff{
147147
BlockNumber: block0.Number().Int64(),
148148
BlockHash: block0Hash,
149149
CreatedAccounts: emptyAccountDiffEventualMap,
@@ -177,7 +177,7 @@ var _ = ginkgo.FDescribe("", func() {
177177
})
178178

179179
ginkgo.It("returns balance diffs for updated accounts", func() {
180-
expectedBankBalanceDiff := statediff.DiffBigInt{
180+
expectedBankBalanceDiff := b.DiffBigInt{
181181
NewValue: big.NewInt(testBankFunds.Int64() - balanceChange),
182182
OldValue: testBankFunds,
183183
}
@@ -187,12 +187,12 @@ var _ = ginkgo.FDescribe("", func() {
187187
})
188188

189189
ginkgo.It("returns balance diffs for new accounts", func() {
190-
expectedAccount1BalanceDiff := statediff.DiffBigInt{
190+
expectedAccount1BalanceDiff := b.DiffBigInt{
191191
NewValue: big.NewInt(balanceChange),
192192
OldValue: nil,
193193
}
194194

195-
expectedBurnAddrBalanceDiff := statediff.DiffBigInt{
195+
expectedBurnAddrBalanceDiff := b.DiffBigInt{
196196
NewValue: big.NewInt(miningReward),
197197
OldValue: nil,
198198
}
@@ -228,17 +228,17 @@ var _ = ginkgo.FDescribe("", func() {
228228
})
229229

230230
ginkgo.It("returns balance diffs for updated accounts", func() {
231-
expectedBankBalanceDiff := statediff.DiffBigInt{
231+
expectedBankBalanceDiff := b.DiffBigInt{
232232
NewValue: big.NewInt(block1BankBalance - balanceChange),
233233
OldValue: big.NewInt(block1BankBalance),
234234
}
235235

236-
expectedAccount1BalanceDiff := statediff.DiffBigInt{
236+
expectedAccount1BalanceDiff := b.DiffBigInt{
237237
NewValue: big.NewInt(block1Account1Balance - balanceChange + balanceChange),
238238
OldValue: big.NewInt(block1Account1Balance),
239239
}
240240

241-
expectedBurnBalanceDiff := statediff.DiffBigInt{
241+
expectedBurnBalanceDiff := b.DiffBigInt{
242242
NewValue: big.NewInt(miningReward + miningReward),
243243
OldValue: big.NewInt(miningReward),
244244
}
@@ -250,12 +250,12 @@ var _ = ginkgo.FDescribe("", func() {
250250
})
251251

252252
ginkgo.It("returns balance diffs for new accounts", func() {
253-
expectedAccount2BalanceDiff := statediff.DiffBigInt{
253+
expectedAccount2BalanceDiff := b.DiffBigInt{
254254
NewValue: big.NewInt(balanceChange),
255255
OldValue: nil,
256256
}
257257

258-
expectedContractBalanceDiff := statediff.DiffBigInt{
258+
expectedContractBalanceDiff := b.DiffBigInt{
259259
NewValue: big.NewInt(0),
260260
OldValue: nil,
261261
}
@@ -290,23 +290,23 @@ var _ = ginkgo.FDescribe("", func() {
290290

291291
ginkgo.It("returns balance, storage and nonce diffs for updated accounts", func() {
292292
block2Account2Balance := int64(1000)
293-
expectedAcct2BalanceDiff := statediff.DiffBigInt{
293+
expectedAcct2BalanceDiff := b.DiffBigInt{
294294
NewValue: big.NewInt(block2Account2Balance + miningReward),
295295
OldValue: big.NewInt(block2Account2Balance),
296296
}
297297

298-
expectedContractStorageDiff := make(map[string]statediff.DiffString)
298+
expectedContractStorageDiff := make(map[string]b.DiffString)
299299
newVal := "0x03"
300300
oldVal := "0x0"
301301
path := "0x405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace"
302-
expectedContractStorageDiff[path] = statediff.DiffString{
302+
expectedContractStorageDiff[path] = b.DiffString{
303303
NewValue: &newVal,
304304
OldValue: &oldVal,
305305
}
306306

307307
oldNonce := uint64(2)
308308
newNonce := uint64(3)
309-
expectedBankNonceDiff := statediff.DiffUint64{
309+
expectedBankNonceDiff := b.DiffUint64{
310310
NewValue: &newNonce,
311311
OldValue: &oldNonce,
312312
}

statediff/helpers.go renamed to statediff/builder/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Contains a batch of utility type declarations used by the tests. As the node
1818
// operates on unique types, a lot of them are needed to check various features.
1919

20-
package statediff
20+
package builder
2121

2222
import (
2323
"sort"

statediff/struct.go renamed to statediff/builder/struct.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Contains a batch of utility type declarations used by the tests. As the node
1818
// operates on unique types, a lot of them are needed to check various features.
1919

20-
package statediff
20+
package builder
2121

2222
import (
2323
"encoding/json"

statediff/extractor.go renamed to statediff/extractor/extractor.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,24 @@
1717
// Contains a batch of utility type declarations used by the tests. As the node
1818
// operates on unique types, a lot of them are needed to check various features.
1919

20-
package statediff
20+
package extractor
2121

2222
import (
2323
"github.com/ethereum/go-ethereum/core/types"
24+
"github.com/ethereum/go-ethereum/statediff/builder"
25+
"github.com/ethereum/go-ethereum/statediff/publisher"
2426
)
2527

2628
type Extractor interface {
2729
ExtractStateDiff(parent, current types.Block) (string, error)
2830
}
2931

3032
type extractor struct {
31-
Builder Builder // Interface for building state diff objects from two blocks
32-
Publisher Publisher // Interface for publishing state diff objects to a datastore (e.g. IPFS)
33+
Builder builder.Builder // Interface for building state diff objects from two blocks
34+
Publisher publisher.Publisher // Interface for publishing state diff objects to a datastore (e.g. IPFS)
3335
}
3436

35-
func NewExtractor(builder Builder, publisher Publisher) (*extractor, error) {
37+
func NewExtractor(builder builder.Builder, publisher publisher.Publisher) (*extractor, error) {
3638
return &extractor{
3739
Builder: builder,
3840
Publisher: publisher,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package extractor_test
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestExtractor(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "Extractor Suite")
13+
}

statediff/extractor_test.go renamed to statediff/extractor/extractor_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,31 @@
1717
// Contains a batch of utility type declarations used by the tests. As the node
1818
// operates on unique types, a lot of them are needed to check various features.
1919

20-
package statediff_test
20+
package extractor_test
2121

2222
import (
2323
"github.com/onsi/ginkgo"
24-
"github.com/ethereum/go-ethereum/statediff"
2524
"github.com/onsi/gomega"
2625
"github.com/ethereum/go-ethereum/core/types"
2726
"math/rand"
2827
"github.com/ethereum/go-ethereum/statediff/testhelpers"
2928
"math/big"
29+
e "github.com/ethereum/go-ethereum/statediff/extractor"
30+
b "github.com/ethereum/go-ethereum/statediff/builder"
3031
)
3132
var _ = ginkgo.Describe("Extractor", func() {
3233
var publisher testhelpers.MockPublisher
3334
var builder testhelpers.MockBuilder
3435
var currentBlockNumber *big.Int
3536
var parentBlock, currentBlock *types.Block
36-
var expectedStateDiff statediff.StateDiff
37-
var extractor statediff.Extractor
37+
var expectedStateDiff b.StateDiff
38+
var extractor e.Extractor
3839
var err error
3940

4041
ginkgo.BeforeEach(func() {
4142
publisher = testhelpers.MockPublisher{}
4243
builder = testhelpers.MockBuilder{}
43-
extractor, err = statediff.NewExtractor(&builder, &publisher)
44+
extractor, err = e.NewExtractor(&builder, &publisher)
4445
gomega.Expect(err).NotTo(gomega.HaveOccurred())
4546

4647
blockNumber := rand.Int63()
@@ -49,7 +50,7 @@ var _ = ginkgo.Describe("Extractor", func() {
4950
parentBlock = types.NewBlock(&types.Header{Number: parentBlockNumber}, nil, nil, nil)
5051
currentBlock = types.NewBlock(&types.Header{Number: currentBlockNumber}, nil, nil, nil)
5152

52-
expectedStateDiff = statediff.StateDiff{
53+
expectedStateDiff = b.StateDiff{
5354
BlockNumber: blockNumber,
5455
BlockHash: currentBlock.Hash(),
5556
CreatedAccounts: nil,

statediff/ipfs/adder.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)