Skip to content

Commit

Permalink
Merge pull request #162 from vulcanize/log_processing_bug
Browse files Browse the repository at this point in the history
Log processing bug fix
  • Loading branch information
i-norden authored Nov 30, 2021
2 parents 9f0ef4a + 963ed83 commit 40be2f9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
Empty file.
9 changes: 1 addition & 8 deletions statediff/indexer/ipld/eth_log_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,8 @@ func (rt *logTrie) getNodeFromDB(key []byte) (*EthLogTrie, error) {
if err != nil {
return nil, err
}

c, err := RawdataToCid(MEthLogTrie, rawdata, multihash.KECCAK_256)
if err != nil {
return nil, err
}

tn := &TrieNode{
cid: c,
cid: keccak256ToCid(MEthLogTrie, key),
rawdata: rawdata,
}
return &EthLogTrie{TrieNode: tn}, nil
Expand All @@ -134,7 +128,6 @@ func (rt *logTrie) getLeafNodes() ([]*EthLogTrie, []*nodeKey, error) {
if err != nil {
return nil, nil, err
}

out := make([]*EthLogTrie, 0, len(keys))
for _, k := range keys {
n, err := rt.getNodeFromDB(k.dbKey)
Expand Down
20 changes: 16 additions & 4 deletions statediff/indexer/ipld/eth_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,24 @@ func processReceiptsAndLogs(rcts []*types.Receipt, expectedRctRoot []byte) ([]*E
return ethRctNodes, rctTrieNodes, ethLogTrieNodes, ethLogleafNodeCids, ethRctleafNodeCids, err
}

const keccak256Length = 32

func processLogs(logs []*types.Log) ([]*EthLogTrie, []cid.Cid, common.Hash, error) {
logTr := newLogTrie()
shortLogCIDs := make(map[uint64]cid.Cid, len(logs))
for idx, log := range logs {
ethLog, err := NewLog(log)
logRaw, err := rlp.EncodeToBytes(log)
if err != nil {
return nil, nil, common.Hash{}, err
}
if err = logTr.Add(idx, ethLog.RawData()); err != nil {
if len(logRaw) <= keccak256Length {
logNode, err := NewLog(log)
if err != nil {
return nil, nil, common.Hash{}, err
}
shortLogCIDs[uint64(idx)] = logNode.Cid()
}
if err = logTr.Add(idx, logRaw); err != nil {
return nil, nil, common.Hash{}, err
}
}
Expand All @@ -259,8 +269,7 @@ func processLogs(logs []*types.Log) ([]*EthLogTrie, []cid.Cid, common.Hash, erro
if err != nil {
return nil, nil, common.Hash{}, err
}

leafNodeCids := make([]cid.Cid, len(leafNodes))
leafNodeCids := make([]cid.Cid, len(logs))
for i, ln := range leafNodes {
var idx uint

Expand All @@ -271,6 +280,9 @@ func processLogs(logs []*types.Log) ([]*EthLogTrie, []cid.Cid, common.Hash, erro
}
leafNodeCids[idx] = ln.Cid()
}
for idx, lCID := range shortLogCIDs {
leafNodeCids[idx] = lCID
}

return logTrieNodes, leafNodeCids, common.BytesToHash(logTr.rootHash()), err
}
8 changes: 1 addition & 7 deletions statediff/indexer/ipld/eth_receipt_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,8 @@ func (rt *rctTrie) getNodeFromDB(key []byte) (*EthRctTrie, error) {
if err != nil {
return nil, err
}

cid, err := RawdataToCid(MEthTxReceiptTrie, rawdata, multihash.KECCAK_256)
if err != nil {
return nil, err
}

tn := &TrieNode{
cid: cid,
cid: keccak256ToCid(MEthStateTrie, key),
rawdata: rawdata,
}

Expand Down
6 changes: 1 addition & 5 deletions statediff/indexer/ipld/eth_tx_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,8 @@ func (tt *txTrie) getNodes() ([]*EthTxTrie, error) {
if err != nil {
return nil, err
}
c, err := RawdataToCid(MEthTxTrie, rawdata, multihash.KECCAK_256)
if err != nil {
return nil, err
}
tn := &TrieNode{
cid: c,
cid: keccak256ToCid(MEthTxTrie, k),
rawdata: rawdata,
}
out = append(out, &EthTxTrie{TrieNode: tn})
Expand Down

0 comments on commit 40be2f9

Please sign in to comment.