Skip to content

Commit 639af8b

Browse files
authored
Merge pull request #102 from vulcanize/log-table
Create a seperate table for storing logs.
2 parents ae82f95 + ca7f7d7 commit 639af8b

23 files changed

+762
-207
lines changed

.github/workflows/on-master.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ jobs:
3333
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u vulcanize --password-stdin
3434
- name: Docker Push
3535
run: docker push docker.pkg.github.com/vulcanize/go-ethereum/go-ethereum:${{steps.vars.outputs.sha}}
36-

core/types/receipt.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type Receipt struct {
7070
BlockHash common.Hash `json:"blockHash,omitempty"`
7171
BlockNumber *big.Int `json:"blockNumber,omitempty"`
7272
TransactionIndex uint `json:"transactionIndex"`
73+
LogRoot common.Hash `json:"logRoot"`
7374
}
7475

7576
type receiptMarshaling struct {
@@ -211,7 +212,7 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error {
211212
}
212213
}
213214

214-
// UnmarshalBinary decodes the canonical encoding of receipts.
215+
// UnmarshalBinary decodes the consensus encoding of receipts.
215216
// It supports legacy RLP receipts and EIP-2718 typed receipts.
216217
func (r *Receipt) UnmarshalBinary(b []byte) error {
217218
if len(b) > 0 && b[0] > 0x7f {
@@ -234,13 +235,13 @@ func (r *Receipt) decodeTyped(b []byte) error {
234235
return errEmptyTypedReceipt
235236
}
236237
switch b[0] {
237-
case AccessListTxType:
238+
case DynamicFeeTxType, AccessListTxType:
238239
var data receiptRLP
239240
err := rlp.DecodeBytes(b[1:], &data)
240241
if err != nil {
241242
return err
242243
}
243-
r.Type = AccessListTxType
244+
r.Type = b[0]
244245
return r.setFromRLP(data)
245246
default:
246247
return ErrTxTypeNotSupported

statediff/builder.go

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/ethereum/go-ethereum/crypto"
3030
"github.com/ethereum/go-ethereum/log"
3131
"github.com/ethereum/go-ethereum/rlp"
32+
sdtrie "github.com/ethereum/go-ethereum/statediff/trie"
3233
. "github.com/ethereum/go-ethereum/statediff/types"
3334
"github.com/ethereum/go-ethereum/trie"
3435
)
@@ -51,28 +52,6 @@ type builder struct {
5152
stateCache state.Database
5253
}
5354

54-
func resolveNode(it trie.NodeIterator, trieDB *trie.Database) (StateNode, []interface{}, error) {
55-
nodePath := make([]byte, len(it.Path()))
56-
copy(nodePath, it.Path())
57-
node, err := trieDB.Node(it.Hash())
58-
if err != nil {
59-
return StateNode{}, nil, err
60-
}
61-
var nodeElements []interface{}
62-
if err := rlp.DecodeBytes(node, &nodeElements); err != nil {
63-
return StateNode{}, nil, err
64-
}
65-
ty, err := CheckKeyType(nodeElements)
66-
if err != nil {
67-
return StateNode{}, nil, err
68-
}
69-
return StateNode{
70-
NodeType: ty,
71-
Path: nodePath,
72-
NodeValue: node,
73-
}, nodeElements, nil
74-
}
75-
7655
// convenience
7756
func stateNodeAppender(nodes *[]StateNode) StateNodeSink {
7857
return func(node StateNode) error {
@@ -127,7 +106,7 @@ func (sdb *builder) buildStateTrie(it trie.NodeIterator) ([]StateNode, []CodeAnd
127106
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
128107
continue
129108
}
130-
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
109+
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
131110
if err != nil {
132111
return nil, nil, err
133112
}
@@ -319,7 +298,7 @@ func (sdb *builder) createdAndUpdatedState(a, b trie.NodeIterator, watchedAddres
319298
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
320299
continue
321300
}
322-
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
301+
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
323302
if err != nil {
324303
return nil, nil, err
325304
}
@@ -363,7 +342,7 @@ func (sdb *builder) createdAndUpdatedStateWithIntermediateNodes(a, b trie.NodeIt
363342
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
364343
continue
365344
}
366-
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
345+
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
367346
if err != nil {
368347
return nil, nil, err
369348
}
@@ -415,7 +394,7 @@ func (sdb *builder) deletedOrUpdatedState(a, b trie.NodeIterator, diffPathsAtB m
415394
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
416395
continue
417396
}
418-
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
397+
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
419398
if err != nil {
420399
return nil, err
421400
}
@@ -576,7 +555,7 @@ func (sdb *builder) buildStorageNodesFromTrie(it trie.NodeIterator, watchedStora
576555
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
577556
continue
578557
}
579-
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
558+
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
580559
if err != nil {
581560
return err
582561
}
@@ -650,7 +629,7 @@ func (sdb *builder) createdAndUpdatedStorage(a, b trie.NodeIterator, watchedKeys
650629
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
651630
continue
652631
}
653-
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
632+
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
654633
if err != nil {
655634
return nil, err
656635
}
@@ -695,7 +674,7 @@ func (sdb *builder) deletedOrUpdatedStorage(a, b trie.NodeIterator, diffPathsAtB
695674
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
696675
continue
697676
}
698-
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
677+
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
699678
if err != nil {
700679
return err
701680
}

statediff/db/migrations/00007_create_eth_receipt_cids_table.sql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ CREATE TABLE eth.receipt_cids (
66
mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
77
contract VARCHAR(66),
88
contract_hash VARCHAR(66),
9-
topic0s VARCHAR(66)[],
10-
topic1s VARCHAR(66)[],
11-
topic2s VARCHAR(66)[],
12-
topic3s VARCHAR(66)[],
13-
log_contracts VARCHAR(66)[],
149
post_state VARCHAR(66),
1510
post_status INTEGER,
11+
log_root VARCHAR(66),
1612
UNIQUE (tx_id)
1713
);
1814

1915
-- +goose Down
20-
DROP TABLE eth.receipt_cids;
16+
DROP TABLE eth.receipt_cids;

statediff/db/migrations/00013_create_cid_indexes.sql

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract);
3636

3737
CREATE INDEX rct_contract_hash_index ON eth.receipt_cids USING btree (contract_hash);
3838

39-
CREATE INDEX rct_topic0_index ON eth.receipt_cids USING gin (topic0s);
40-
41-
CREATE INDEX rct_topic1_index ON eth.receipt_cids USING gin (topic1s);
42-
43-
CREATE INDEX rct_topic2_index ON eth.receipt_cids USING gin (topic2s);
44-
45-
CREATE INDEX rct_topic3_index ON eth.receipt_cids USING gin (topic3s);
46-
47-
CREATE INDEX rct_log_contract_index ON eth.receipt_cids USING gin (log_contracts);
48-
4939
-- state node indexes
5040
CREATE INDEX state_header_id_index ON eth.state_cids USING btree (header_id);
5141

@@ -93,11 +83,6 @@ DROP INDEX eth.state_leaf_key_index;
9383
DROP INDEX eth.state_header_id_index;
9484

9585
-- receipt indexes
96-
DROP INDEX eth.rct_log_contract_index;
97-
DROP INDEX eth.rct_topic3_index;
98-
DROP INDEX eth.rct_topic2_index;
99-
DROP INDEX eth.rct_topic1_index;
100-
DROP INDEX eth.rct_topic0_index;
10186
DROP INDEX eth.rct_contract_hash_index;
10287
DROP INDEX eth.rct_contract_index;
10388
DROP INDEX eth.rct_mh_index;
@@ -118,4 +103,4 @@ DROP INDEX eth.state_root_index;
118103
DROP INDEX eth.header_mh_index;
119104
DROP INDEX eth.header_cid_index;
120105
DROP INDEX eth.block_hash_index;
121-
DROP INDEX eth.block_number_index;
106+
DROP INDEX eth.block_number_index;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
-- +goose Up
2+
CREATE TABLE eth.log_cids (
3+
id SERIAL PRIMARY KEY,
4+
leaf_cid TEXT NOT NULL,
5+
leaf_mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
6+
receipt_id INTEGER NOT NULL REFERENCES eth.receipt_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
7+
address VARCHAR(66),
8+
log_data BYTEA,
9+
index INTEGER NOT NULL,
10+
topic0 VARCHAR(66),
11+
topic1 VARCHAR(66),
12+
topic2 VARCHAR(66),
13+
topic3 VARCHAR(66),
14+
UNIQUE (receipt_id, index)
15+
);
16+
17+
CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key);
18+
19+
CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid);
20+
21+
CREATE INDEX log_rct_id_index ON eth.log_cids USING btree (receipt_id);
22+
--
23+
-- Name: log_topic0_index; Type: INDEX; Schema: eth; Owner: -
24+
--
25+
26+
CREATE INDEX log_topic0_index ON eth.log_cids USING btree (topic0);
27+
28+
29+
--
30+
-- Name: log_topic1_index; Type: INDEX; Schema: eth; Owner: -
31+
--
32+
33+
CREATE INDEX log_topic1_index ON eth.log_cids USING btree (topic1);
34+
35+
36+
--
37+
-- Name: log_topic2_index; Type: INDEX; Schema: eth; Owner: -
38+
--
39+
40+
CREATE INDEX log_topic2_index ON eth.log_cids USING btree (topic2);
41+
42+
43+
--
44+
-- Name: log_topic3_index; Type: INDEX; Schema: eth; Owner: -
45+
--
46+
47+
CREATE INDEX log_topic3_index ON eth.log_cids USING btree (topic3);
48+
49+
50+
-- +goose Down
51+
-- log indexes
52+
DROP INDEX eth.log_mh_index;
53+
DROP INDEX eth.log_cid_index;
54+
DROP INDEX eth.log_rct_id_index;
55+
DROP INDEX eth.log_topic0_index;
56+
DROP INDEX eth.log_topic1_index;
57+
DROP INDEX eth.log_topic2_index;
58+
DROP INDEX eth.log_topic3_index;
59+
60+
DROP TABLE eth.log_cids;

statediff/db/schema.sql

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -998,34 +998,6 @@ CREATE INDEX rct_log_contract_index ON eth.receipt_cids USING gin (log_contracts
998998
CREATE INDEX rct_mh_index ON eth.receipt_cids USING btree (mh_key);
999999

10001000

1001-
--
1002-
-- Name: rct_topic0_index; Type: INDEX; Schema: eth; Owner: -
1003-
--
1004-
1005-
CREATE INDEX rct_topic0_index ON eth.receipt_cids USING gin (topic0s);
1006-
1007-
1008-
--
1009-
-- Name: rct_topic1_index; Type: INDEX; Schema: eth; Owner: -
1010-
--
1011-
1012-
CREATE INDEX rct_topic1_index ON eth.receipt_cids USING gin (topic1s);
1013-
1014-
1015-
--
1016-
-- Name: rct_topic2_index; Type: INDEX; Schema: eth; Owner: -
1017-
--
1018-
1019-
CREATE INDEX rct_topic2_index ON eth.receipt_cids USING gin (topic2s);
1020-
1021-
1022-
--
1023-
-- Name: rct_topic3_index; Type: INDEX; Schema: eth; Owner: -
1024-
--
1025-
1026-
CREATE INDEX rct_topic3_index ON eth.receipt_cids USING gin (topic3s);
1027-
1028-
10291001
--
10301002
-- Name: rct_tx_id_index; Type: INDEX; Schema: eth; Owner: -
10311003
--
@@ -1330,4 +1302,3 @@ ALTER TABLE ONLY eth.uncle_cids
13301302
--
13311303
-- PostgreSQL database dump complete
13321304
--
1333-

statediff/helpers.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
package statediff
2121

2222
import (
23-
"fmt"
2423
"sort"
2524
"strings"
26-
27-
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
2825
)
2926

3027
func sortKeys(data AccountMap) []string {
@@ -74,25 +71,3 @@ func findIntersection(a, b []string) []string {
7471
}
7572

7673
}
77-
78-
// CheckKeyType checks what type of key we have
79-
func CheckKeyType(elements []interface{}) (sdtypes.NodeType, error) {
80-
if len(elements) > 2 {
81-
return sdtypes.Branch, nil
82-
}
83-
if len(elements) < 2 {
84-
return sdtypes.Unknown, fmt.Errorf("node cannot be less than two elements in length")
85-
}
86-
switch elements[0].([]byte)[0] / 16 {
87-
case '\x00':
88-
return sdtypes.Extension, nil
89-
case '\x01':
90-
return sdtypes.Extension, nil
91-
case '\x02':
92-
return sdtypes.Leaf, nil
93-
case '\x03':
94-
return sdtypes.Leaf, nil
95-
default:
96-
return sdtypes.Unknown, fmt.Errorf("unknown hex prefix")
97-
}
98-
}

0 commit comments

Comments
 (0)