Skip to content

Commit daa2cdd

Browse files
authored
Merge pull request #56 from vulcanize/v1.10.1-statediff-0.0.15
V1.10.1 statediff 0.0.15
2 parents 6e4725a + 5cb5773 commit daa2cdd

File tree

9 files changed

+95
-48
lines changed

9 files changed

+95
-48
lines changed

.github/workflows/on-master.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Docker Build and publish to Github
33
on:
44
push:
55
branches:
6+
- v1.10.1-statediff
67
- v1.9.25-statediff
78
- v1.9.24-statediff
89
- v1.9.23-statediff

cmd/geth/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
180180
EnableWriteLoop: ctx.GlobalBool(utils.StateDiffWritingFlag.Name),
181181
NumWorkers: ctx.GlobalUint(utils.StateDiffWorkersFlag.Name),
182182
}
183-
utils.RegisterStateDiffService(stack, backend, params)
183+
utils.RegisterStateDiffService(stack, backend, &cfg.Eth, params)
184184
}
185185

186186
// Configure GraphQL if requested

cmd/utils/flags.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import (
4646
"github.com/ethereum/go-ethereum/eth/downloader"
4747
"github.com/ethereum/go-ethereum/eth/ethconfig"
4848
"github.com/ethereum/go-ethereum/eth/gasprice"
49-
"github.com/ethereum/go-ethereum/eth/tracers"
5049
"github.com/ethereum/go-ethereum/ethdb"
5150
"github.com/ethereum/go-ethereum/ethstats"
5251
"github.com/ethereum/go-ethereum/graphql"
@@ -1735,8 +1734,8 @@ func RegisterGraphQLService(stack *node.Node, backend ethapi.Backend, cfg node.C
17351734
}
17361735

17371736
// RegisterStateDiffService configures and registers a service to stream state diff data over RPC
1738-
func RegisterStateDiffService(stack *node.Node, ethServ *eth.Ethereum, params statediff.ServiceParams) {
1739-
if err := statediff.New(stack, ethServ, params); err != nil {
1737+
func RegisterStateDiffService(stack *node.Node, ethServ *eth.Ethereum, cfg *ethconfig.Config, params statediff.ServiceParams) {
1738+
if err := statediff.New(stack, ethServ, cfg, params); err != nil {
17401739
Fatalf("Failed to register the Statediff service: %v", err)
17411740
}
17421741
}

miner/stress_clique.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/ethereum/go-ethereum/crypto"
3737
"github.com/ethereum/go-ethereum/eth"
3838
"github.com/ethereum/go-ethereum/eth/downloader"
39+
"github.com/ethereum/go-ethereum/eth/ethconfig"
3940
"github.com/ethereum/go-ethereum/log"
4041
"github.com/ethereum/go-ethereum/miner"
4142
"github.com/ethereum/go-ethereum/node"

miner/stress_ethash.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/ethereum/go-ethereum/crypto"
3838
"github.com/ethereum/go-ethereum/eth"
3939
"github.com/ethereum/go-ethereum/eth/downloader"
40+
"github.com/ethereum/go-ethereum/eth/ethconfig"
4041
"github.com/ethereum/go-ethereum/log"
4142
"github.com/ethereum/go-ethereum/miner"
4243
"github.com/ethereum/go-ethereum/node"

params/version.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
)
2222

2323
const (
24-
VersionMajor = 1 // Major version component of the current release
25-
VersionMinor = 10 // Minor version component of the current release
26-
VersionPatch = 1 // Patch version component of the current release
27-
VersionMeta = "stable" // Version metadata to append to the version string
24+
VersionMajor = 1 // Major version component of the current release
25+
VersionMinor = 10 // Minor version component of the current release
26+
VersionPatch = 1 // Patch version component of the current release
27+
VersionMeta = "statediff-0.0.15" // Version metadata to append to the version string
2828
)
2929

3030
// Version holds the textual version string.

statediff/indexer/indexer_test.go

Lines changed: 80 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
package indexer_test
1818

1919
import (
20+
"bytes"
2021
"testing"
2122

23+
"github.com/ethereum/go-ethereum/core/types"
24+
2225
"github.com/ethereum/go-ethereum/common"
2326
"github.com/ethereum/go-ethereum/params"
2427
"github.com/ethereum/go-ethereum/statediff/indexer"
28+
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs/ipld"
2529
"github.com/ethereum/go-ethereum/statediff/indexer/mocks"
2630
"github.com/ethereum/go-ethereum/statediff/indexer/models"
2731
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
@@ -30,6 +34,7 @@ import (
3034
"github.com/ipfs/go-cid"
3135
blockstore "github.com/ipfs/go-ipfs-blockstore"
3236
dshelp "github.com/ipfs/go-ipfs-ds-help"
37+
"github.com/multiformats/go-multihash"
3338
)
3439

3540
var (
@@ -38,6 +43,11 @@ var (
3843
ind *indexer.StateDiffIndexer
3944
ipfsPgGet = `SELECT data FROM public.blocks
4045
WHERE key = $1`
46+
tx1, tx2, tx3, rct1, rct2, rct3 []byte
47+
mockBlock *types.Block
48+
headerCID, trx1CID, trx2CID, trx3CID cid.Cid
49+
rct1CID, rct2CID, rct3CID cid.Cid
50+
state1CID, state2CID, storageCID cid.Cid
4151
)
4252

4353
func expectTrue(t *testing.T, value bool) {
@@ -46,6 +56,53 @@ func expectTrue(t *testing.T, value bool) {
4656
}
4757
}
4858

59+
func init() {
60+
mockBlock = mocks.MockBlock
61+
txs, rcts := mocks.MockBlock.Transactions(), mocks.MockReceipts
62+
63+
buf := new(bytes.Buffer)
64+
txs.EncodeIndex(0, buf)
65+
tx1 = make([]byte, buf.Len())
66+
copy(tx1, buf.Bytes())
67+
buf.Reset()
68+
69+
txs.EncodeIndex(1, buf)
70+
tx2 = make([]byte, buf.Len())
71+
copy(tx2, buf.Bytes())
72+
buf.Reset()
73+
74+
txs.EncodeIndex(2, buf)
75+
tx3 = make([]byte, buf.Len())
76+
copy(tx3, buf.Bytes())
77+
buf.Reset()
78+
79+
rcts.EncodeIndex(0, buf)
80+
rct1 = make([]byte, buf.Len())
81+
copy(rct1, buf.Bytes())
82+
buf.Reset()
83+
84+
rcts.EncodeIndex(1, buf)
85+
rct2 = make([]byte, buf.Len())
86+
copy(rct2, buf.Bytes())
87+
buf.Reset()
88+
89+
rcts.EncodeIndex(2, buf)
90+
rct3 = make([]byte, buf.Len())
91+
copy(rct3, buf.Bytes())
92+
buf.Reset()
93+
94+
headerCID, _ = ipld.RawdataToCid(ipld.MEthHeader, mocks.MockHeaderRlp, multihash.KECCAK_256)
95+
trx1CID, _ = ipld.RawdataToCid(ipld.MEthTx, tx1, multihash.KECCAK_256)
96+
trx2CID, _ = ipld.RawdataToCid(ipld.MEthTx, tx2, multihash.KECCAK_256)
97+
trx3CID, _ = ipld.RawdataToCid(ipld.MEthTx, tx3, multihash.KECCAK_256)
98+
rct1CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, rct1, multihash.KECCAK_256)
99+
rct2CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, rct2, multihash.KECCAK_256)
100+
rct3CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, rct3, multihash.KECCAK_256)
101+
state1CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, mocks.ContractLeafNode, multihash.KECCAK_256)
102+
state2CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, mocks.AccountLeafNode, multihash.KECCAK_256)
103+
storageCID, _ = ipld.RawdataToCid(ipld.MEthStorageTrie, mocks.StorageLeafNode, multihash.KECCAK_256)
104+
}
105+
49106
func setup(t *testing.T) {
50107
db, err = shared.SetupDB()
51108
if err != nil {
@@ -54,7 +111,7 @@ func setup(t *testing.T) {
54111
ind = indexer.NewStateDiffIndexer(params.MainnetChainConfig, db)
55112
var tx *indexer.BlockTx
56113
tx, err = ind.PushBlock(
57-
mocks.MockBlock,
114+
mockBlock,
58115
mocks.MockReceipts,
59116
mocks.MockBlock.Difficulty())
60117
if err != nil {
@@ -94,7 +151,7 @@ func TestPublishAndIndexer(t *testing.T) {
94151
if err != nil {
95152
t.Fatal(err)
96153
}
97-
shared.ExpectEqual(t, header.CID, mocks.HeaderCID.String())
154+
shared.ExpectEqual(t, header.CID, headerCID.String())
98155
shared.ExpectEqual(t, header.TD, mocks.MockBlock.Difficulty().String())
99156
shared.ExpectEqual(t, header.Reward, "5000000000000011250")
100157
dc, err := cid.Decode(header.CID)
@@ -123,9 +180,9 @@ func TestPublishAndIndexer(t *testing.T) {
123180
t.Fatal(err)
124181
}
125182
shared.ExpectEqual(t, len(trxs), 3)
126-
expectTrue(t, shared.ListContainsString(trxs, mocks.Trx1CID.String()))
127-
expectTrue(t, shared.ListContainsString(trxs, mocks.Trx2CID.String()))
128-
expectTrue(t, shared.ListContainsString(trxs, mocks.Trx3CID.String()))
183+
expectTrue(t, shared.ListContainsString(trxs, trx1CID.String()))
184+
expectTrue(t, shared.ListContainsString(trxs, trx2CID.String()))
185+
expectTrue(t, shared.ListContainsString(trxs, trx3CID.String()))
129186
// and published
130187
for _, c := range trxs {
131188
dc, err := cid.Decode(c)
@@ -140,12 +197,12 @@ func TestPublishAndIndexer(t *testing.T) {
140197
t.Fatal(err)
141198
}
142199
switch c {
143-
case mocks.Trx1CID.String():
144-
shared.ExpectEqual(t, data, mocks.MockTransactions.GetRlp(0))
145-
case mocks.Trx2CID.String():
146-
shared.ExpectEqual(t, data, mocks.MockTransactions.GetRlp(1))
147-
case mocks.Trx3CID.String():
148-
shared.ExpectEqual(t, data, mocks.MockTransactions.GetRlp(2))
200+
case trx1CID.String():
201+
shared.ExpectEqual(t, data, tx1)
202+
case trx2CID.String():
203+
shared.ExpectEqual(t, data, tx2)
204+
case trx3CID.String():
205+
shared.ExpectEqual(t, data, tx3)
149206
}
150207
}
151208
})
@@ -164,9 +221,9 @@ func TestPublishAndIndexer(t *testing.T) {
164221
t.Fatal(err)
165222
}
166223
shared.ExpectEqual(t, len(rcts), 3)
167-
expectTrue(t, shared.ListContainsString(rcts, mocks.Rct1CID.String()))
168-
expectTrue(t, shared.ListContainsString(rcts, mocks.Rct2CID.String()))
169-
expectTrue(t, shared.ListContainsString(rcts, mocks.Rct3CID.String()))
224+
expectTrue(t, shared.ListContainsString(rcts, rct1CID.String()))
225+
expectTrue(t, shared.ListContainsString(rcts, rct2CID.String()))
226+
expectTrue(t, shared.ListContainsString(rcts, rct3CID.String()))
170227
// and published
171228
for _, c := range rcts {
172229
dc, err := cid.Decode(c)
@@ -181,26 +238,26 @@ func TestPublishAndIndexer(t *testing.T) {
181238
t.Fatal(err)
182239
}
183240
switch c {
184-
case mocks.Rct1CID.String():
185-
shared.ExpectEqual(t, data, mocks.MockReceipts.GetRlp(0))
241+
case rct1CID.String():
242+
shared.ExpectEqual(t, data, rct1)
186243
var postStatus uint64
187244
pgStr = `SELECT post_status FROM eth.receipt_cids WHERE cid = $1`
188245
err = db.Get(&postStatus, pgStr, c)
189246
if err != nil {
190247
t.Fatal(err)
191248
}
192249
shared.ExpectEqual(t, postStatus, mocks.ExpectedPostStatus)
193-
case mocks.Rct2CID.String():
194-
shared.ExpectEqual(t, data, mocks.MockReceipts.GetRlp(1))
250+
case rct2CID.String():
251+
shared.ExpectEqual(t, data, rct2)
195252
var postState string
196253
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE cid = $1`
197254
err = db.Get(&postState, pgStr, c)
198255
if err != nil {
199256
t.Fatal(err)
200257
}
201258
shared.ExpectEqual(t, postState, mocks.ExpectedPostState1)
202-
case mocks.Rct3CID.String():
203-
shared.ExpectEqual(t, data, mocks.MockReceipts.GetRlp(2))
259+
case rct3CID.String():
260+
shared.ExpectEqual(t, data, rct3)
204261
var postState string
205262
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE cid = $1`
206263
err = db.Get(&postState, pgStr, c)
@@ -243,7 +300,7 @@ func TestPublishAndIndexer(t *testing.T) {
243300
if err != nil {
244301
t.Fatal(err)
245302
}
246-
if stateNode.CID == mocks.State1CID.String() {
303+
if stateNode.CID == state1CID.String() {
247304
shared.ExpectEqual(t, stateNode.NodeType, 2)
248305
shared.ExpectEqual(t, stateNode.StateKey, common.BytesToHash(mocks.ContractLeafKey).Hex())
249306
shared.ExpectEqual(t, stateNode.Path, []byte{'\x06'})
@@ -257,7 +314,7 @@ func TestPublishAndIndexer(t *testing.T) {
257314
Nonce: 1,
258315
})
259316
}
260-
if stateNode.CID == mocks.State2CID.String() {
317+
if stateNode.CID == state2CID.String() {
261318
shared.ExpectEqual(t, stateNode.NodeType, 2)
262319
shared.ExpectEqual(t, stateNode.StateKey, common.BytesToHash(mocks.AccountLeafKey).Hex())
263320
shared.ExpectEqual(t, stateNode.Path, []byte{'\x0c'})
@@ -290,7 +347,7 @@ func TestPublishAndIndexer(t *testing.T) {
290347
}
291348
shared.ExpectEqual(t, len(storageNodes), 1)
292349
shared.ExpectEqual(t, storageNodes[0], models.StorageNodeWithStateKeyModel{
293-
CID: mocks.StorageCID.String(),
350+
CID: storageCID.String(),
294351
NodeType: 2,
295352
StorageKey: common.BytesToHash(mocks.StorageLeafKey).Hex(),
296353
StateKey: common.BytesToHash(mocks.ContractLeafKey).Hex(),

statediff/indexer/mocks/test_data.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ import (
3131
"github.com/ethereum/go-ethereum/log"
3232
"github.com/ethereum/go-ethereum/params"
3333
"github.com/ethereum/go-ethereum/rlp"
34-
"github.com/multiformats/go-multihash"
35-
36-
"github.com/ethereum/go-ethereum/statediff/indexer/ipfs/ipld"
3734
"github.com/ethereum/go-ethereum/statediff/testhelpers"
3835
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
3936
)
@@ -52,13 +49,11 @@ var (
5249
Extra: []byte{},
5350
}
5451
MockTransactions, MockReceipts, SenderAddr = createTransactionsAndReceipts()
55-
ReceiptsRlp, _ = rlp.EncodeToBytes(MockReceipts)
5652
MockBlock = types.NewBlock(&MockHeader, MockTransactions, nil, MockReceipts, new(trie.Trie))
5753
MockHeaderRlp, _ = rlp.EncodeToBytes(MockBlock.Header())
5854
Address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
5955
AnotherAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593")
6056
ContractAddress = crypto.CreateAddress(SenderAddr, MockTransactions[2].Nonce())
61-
ContractHash = crypto.Keccak256Hash(ContractAddress.Bytes()).String()
6257
MockContractByteCode = []byte{0, 1, 2, 3, 4, 5}
6358
mockTopic11 = common.HexToHash("0x04")
6459
mockTopic12 = common.HexToHash("0x06")
@@ -77,16 +72,6 @@ var (
7772
Topics: []common.Hash{mockTopic21, mockTopic22},
7873
Data: []byte{},
7974
}
80-
HeaderCID, _ = ipld.RawdataToCid(ipld.MEthHeader, MockHeaderRlp, multihash.KECCAK_256)
81-
Trx1CID, _ = ipld.RawdataToCid(ipld.MEthTx, MockTransactions.GetRlp(0), multihash.KECCAK_256)
82-
Trx2CID, _ = ipld.RawdataToCid(ipld.MEthTx, MockTransactions.GetRlp(1), multihash.KECCAK_256)
83-
Trx3CID, _ = ipld.RawdataToCid(ipld.MEthTx, MockTransactions.GetRlp(2), multihash.KECCAK_256)
84-
Rct1CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, MockReceipts.GetRlp(0), multihash.KECCAK_256)
85-
Rct2CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, MockReceipts.GetRlp(1), multihash.KECCAK_256)
86-
Rct3CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, MockReceipts.GetRlp(2), multihash.KECCAK_256)
87-
State1CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, ContractLeafNode, multihash.KECCAK_256)
88-
State2CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, AccountLeafNode, multihash.KECCAK_256)
89-
StorageCID, _ = ipld.RawdataToCid(ipld.MEthStorageTrie, StorageLeafNode, multihash.KECCAK_256)
9075

9176
// statediff data
9277
storageLocation = common.HexToHash("0")
@@ -193,5 +178,6 @@ func createTransactionsAndReceipts() (types.Transactions, types.Receipts, common
193178
mockReceipt3 := types.NewReceipt(common.HexToHash("0x2").Bytes(), false, 75)
194179
mockReceipt3.Logs = []*types.Log{}
195180
mockReceipt3.TxHash = signedTrx3.Hash()
181+
196182
return types.Transactions{signedTrx1, signedTrx2, signedTrx3}, types.Receipts{mockReceipt1, mockReceipt2, mockReceipt3}, SenderAddr
197183
}

statediff/service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"sync"
2424
"sync/atomic"
2525

26+
"github.com/ethereum/go-ethereum/eth/ethconfig"
27+
2628
"github.com/ethereum/go-ethereum/common"
2729
"github.com/ethereum/go-ethereum/core"
2830
"github.com/ethereum/go-ethereum/core/state"
@@ -146,13 +148,13 @@ func NewBlockCache(max uint) blockCache {
146148

147149
// New creates a new statediff.Service
148150
// func New(stack *node.Node, ethServ *eth.Ethereum, dbParams *DBParams, enableWriteLoop bool) error {
149-
func New(stack *node.Node, ethServ *eth.Ethereum, params ServiceParams) error {
151+
func New(stack *node.Node, ethServ *eth.Ethereum, cfg *ethconfig.Config, params ServiceParams) error {
150152
blockChain := ethServ.BlockChain()
151153
var indexer ind.Indexer
152154
if params.DBParams != nil {
153155
info := nodeinfo.Info{
154156
GenesisBlock: blockChain.Genesis().Hash().Hex(),
155-
NetworkID: strconv.FormatUint(ethServ.NetVersion(), 10),
157+
NetworkID: strconv.FormatUint(cfg.NetworkId, 10),
156158
ChainID: blockChain.Config().ChainID.Uint64(),
157159
ID: params.DBParams.ID,
158160
ClientName: params.DBParams.ClientName,

0 commit comments

Comments
 (0)