Skip to content

Commit 4a73c20

Browse files
authored
Merge pull request #180 from vulcanize/v1.10.14-statediff-0.0.29
V1.10.14 statediff 0.0.29
2 parents f991775 + 61c5cbb commit 4a73c20

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

cmd/geth/config.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/ethereum/go-ethereum/metrics"
4141
"github.com/ethereum/go-ethereum/node"
4242
"github.com/ethereum/go-ethereum/params"
43+
"github.com/ethereum/go-ethereum/statediff"
4344
)
4445

4546
var (
@@ -165,7 +166,35 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
165166
if ctx.GlobalIsSet(utils.OverrideTerminalTotalDifficulty.Name) {
166167
cfg.Eth.OverrideTerminalTotalDifficulty = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideTerminalTotalDifficulty.Name))
167168
}
168-
backend, _ := utils.RegisterEthService(stack, &cfg.Eth, ctx.GlobalBool(utils.CatalystFlag.Name))
169+
backend, eth := utils.RegisterEthService(stack, &cfg.Eth, ctx.GlobalBool(utils.CatalystFlag.Name))
170+
171+
if ctx.GlobalBool(utils.StateDiffFlag.Name) {
172+
var dbParams *statediff.DBParams
173+
if ctx.GlobalIsSet(utils.StateDiffDBFlag.Name) {
174+
dbParams = new(statediff.DBParams)
175+
dbParams.ConnectionURL = ctx.GlobalString(utils.StateDiffDBFlag.Name)
176+
if ctx.GlobalIsSet(utils.StateDiffDBNodeIDFlag.Name) {
177+
dbParams.ID = ctx.GlobalString(utils.StateDiffDBNodeIDFlag.Name)
178+
} else {
179+
utils.Fatalf("Must specify node ID for statediff DB output")
180+
}
181+
if ctx.GlobalIsSet(utils.StateDiffDBClientNameFlag.Name) {
182+
dbParams.ClientName = ctx.GlobalString(utils.StateDiffDBClientNameFlag.Name)
183+
} else {
184+
utils.Fatalf("Must specify client name for statediff DB output")
185+
}
186+
} else {
187+
if ctx.GlobalBool(utils.StateDiffWritingFlag.Name) {
188+
utils.Fatalf("Must pass DB parameters if enabling statediff write loop")
189+
}
190+
}
191+
p := statediff.ServiceParams{
192+
DBParams: dbParams,
193+
EnableWriteLoop: ctx.GlobalBool(utils.StateDiffWritingFlag.Name),
194+
NumWorkers: ctx.GlobalUint(utils.StateDiffWorkersFlag.Name),
195+
}
196+
utils.RegisterStateDiffService(stack, eth, &cfg.Eth, p)
197+
}
169198

170199
// Configure GraphQL if requested
171200
if ctx.GlobalIsSet(utils.GraphQLEnabledFlag.Name) {

cmd/utils/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ var (
796796
Name: "catalyst",
797797
Usage: "Catalyst mode (eth2 integration testing)",
798798
}
799+
799800
StateDiffFlag = cli.BoolFlag{
800801
Name: "statediff",
801802
Usage: "Enables the processing of state diffs between each block",

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
VersionMajor = 1 // Major version component of the current release
2525
VersionMinor = 10 // Minor version component of the current release
2626
VersionPatch = 14 // Patch version component of the current release
27-
VersionMeta = "statediff-0.0.28" // Version metadata to append to the version string
27+
VersionMeta = "statediff-0.0.29" // Version metadata to append to the version string
2828
)
2929

3030
// Version holds the textual version string.

statediff/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,18 @@ This state diffing service runs as an auxiliary service concurrent to the regula
7777
### CLI configuration
7878
This service introduces a CLI flag namespace `statediff`
7979

80-
`--statediff` flag is used to turn on the service
81-
`--statediff.writing` is used to tell the service to write state diff objects it produces from synced ChainEvents directly to a configured Postgres database
82-
`--statediff.workers` is used to set the number of concurrent workers to process state diff objects and write them into the database
83-
`--statediff.db` is the connection string for the Postgres database to write to
84-
`--statediff.db.init` indicates whether we need to initialize a new database; set true if its the first time running the process on a given database
85-
`--statediff.dbnodeid` is the node id to use in the Postgres database
86-
`--statediff.dbclientname` is the client name to use in the Postgres database
80+
`--statediff` flag is used to turn on the service
81+
`--statediff.writing` is used to tell the service to write state diff objects it produces from synced ChainEvents directly to a configured Postgres database
82+
`--statediff.workers` is used to set the number of concurrent workers to process state diff objects and write them into the database
83+
`--statediff.db` is the connection string for the Postgres database to write to
84+
`--statediff.dbnodeid` is the node id to use in the Postgres database
85+
`--statediff.dbclientname` is the client name to use in the Postgres database
8786

8887
The service can only operate in full sync mode (`--syncmode=full`), but only the historical RPC endpoints require an archive node (`--gcmode=archive`)
8988

9089
e.g.
9190
`
92-
./build/bin/geth --syncmode=full --gcmode=archive --statediff --statediff.writing --statediff.db=postgres://localhost:5432/vulcanize_testing?sslmode=disable --statediff.db.init=true --statediff.dbnodeid={nodeId} --statediff.dbclientname={dbClientName}
91+
./build/bin/geth --syncmode=full --gcmode=archive --statediff --statediff.writing --statediff.db='postgres://localhost:5432/vulcanize_testing?sslmode=disable' --statediff.dbnodeid={nodeId} --statediff.dbclientname={dbClientName}
9392
`
9493

9594
### RPC endpoints

statediff/indexer/indexer_test.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ func init() {
125125
trx3CID, _ = ipld.RawdataToCid(ipld.MEthTx, tx3, multihash.KECCAK_256)
126126
trx4CID, _ = ipld.RawdataToCid(ipld.MEthTx, tx4, multihash.KECCAK_256)
127127
trx5CID, _ = ipld.RawdataToCid(ipld.MEthTx, tx5, multihash.KECCAK_256)
128-
/*
129-
rct1Node, _ := ipld.NewReceipt(rcts[0])
130-
rct2Node, _ := ipld.NewReceipt(rcts[1])
131-
rct3Node, _ := ipld.NewReceipt(rcts[2])
132-
rct4Node, _ := ipld.NewReceipt(rcts[3])
133-
rct5Node, _ := ipld.NewReceipt(rcts[4])
134-
*/
135128
state1CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, mocks.ContractLeafNode, multihash.KECCAK_256)
136129
state2CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, mocks.AccountLeafNode, multihash.KECCAK_256)
137130
storageCID, _ = ipld.RawdataToCid(ipld.MEthStorageTrie, mocks.StorageLeafNode, multihash.KECCAK_256)
@@ -241,7 +234,7 @@ func TestPublishAndIndexer(t *testing.T) {
241234
t.Run("Publish and index transaction IPLDs in a single tx", func(t *testing.T) {
242235
setup(t)
243236
defer tearDown(t)
244-
// check that txs were properly indexed
237+
// check that txs were properly indexed and published
245238
trxs := make([]string, 0)
246239
pgStr := `SELECT transaction_cids.cid FROM eth.transaction_cids INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.id)
247240
WHERE header_cids.block_number = $1`
@@ -255,7 +248,7 @@ func TestPublishAndIndexer(t *testing.T) {
255248
expectTrue(t, shared.ListContainsString(trxs, trx3CID.String()))
256249
expectTrue(t, shared.ListContainsString(trxs, trx4CID.String()))
257250
expectTrue(t, shared.ListContainsString(trxs, trx5CID.String()))
258-
// and published
251+
259252
for _, c := range trxs {
260253
dc, err := cid.Decode(c)
261254
if err != nil {
@@ -402,7 +395,7 @@ func TestPublishAndIndexer(t *testing.T) {
402395
setup(t)
403396
defer tearDown(t)
404397

405-
// check receipts were properly indexed
398+
// check receipts were properly indexed and published
406399
rcts := make([]string, 0)
407400
pgStr := `SELECT receipt_cids.leaf_cid FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
408401
WHERE receipt_cids.tx_id = transaction_cids.id
@@ -413,14 +406,19 @@ func TestPublishAndIndexer(t *testing.T) {
413406
t.Fatal(err)
414407
}
415408
shared.ExpectEqual(t, len(rcts), 5)
409+
expectTrue(t, shared.ListContainsString(rcts, rct1CID.String()))
410+
expectTrue(t, shared.ListContainsString(rcts, rct2CID.String()))
411+
expectTrue(t, shared.ListContainsString(rcts, rct3CID.String()))
412+
expectTrue(t, shared.ListContainsString(rcts, rct4CID.String()))
413+
expectTrue(t, shared.ListContainsString(rcts, rct5CID.String()))
416414

417-
for idx, rctLeafCID := range rcts {
415+
for idx, c := range rcts {
418416
result := make([]ipfs.BlockModel, 0)
419417
pgStr = `SELECT data
420418
FROM eth.receipt_cids
421419
INNER JOIN public.blocks ON (receipt_cids.leaf_mh_key = public.blocks.key)
422420
WHERE receipt_cids.leaf_cid = $1`
423-
err = db.Select(&result, pgStr, rctLeafCID)
421+
err = db.Select(&result, pgStr, c)
424422
if err != nil {
425423
t.Fatal(err)
426424
}
@@ -434,10 +432,7 @@ func TestPublishAndIndexer(t *testing.T) {
434432
require.NoError(t, err)
435433

436434
shared.ExpectEqual(t, expectedRct, nodeElements[1].([]byte))
437-
}
438435

439-
// and published
440-
for _, c := range rcts {
441436
dc, err := cid.Decode(c)
442437
if err != nil {
443438
t.Fatal(err)

0 commit comments

Comments
 (0)