log processing bug fix
This commit is contained in:
parent
34da680ab4
commit
f6f548711b
@ -114,14 +114,8 @@ func (rt *logTrie) getNodeFromDB(key []byte) (*EthLogTrie, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := RawdataToCid(MEthLogTrie, rawdata, multihash.KECCAK_256)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
tn := &TrieNode{
|
tn := &TrieNode{
|
||||||
cid: c,
|
cid: keccak256ToCid(MEthLogTrie, key),
|
||||||
rawdata: rawdata,
|
rawdata: rawdata,
|
||||||
}
|
}
|
||||||
return &EthLogTrie{TrieNode: tn}, nil
|
return &EthLogTrie{TrieNode: tn}, nil
|
||||||
|
@ -238,14 +238,30 @@ func processReceiptsAndLogs(rcts []*types.Receipt, expectedRctRoot []byte) ([]*E
|
|||||||
return ethRctNodes, rctTrieNodes, ethLogTrieNodes, ethLogleafNodeCids, ethRctleafNodeCids, err
|
return ethRctNodes, rctTrieNodes, ethLogTrieNodes, ethLogleafNodeCids, ethRctleafNodeCids, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const keccak256Length = 32
|
||||||
|
|
||||||
func processLogs(logs []*types.Log) ([]*EthLogTrie, []cid.Cid, common.Hash, error) {
|
func processLogs(logs []*types.Log) ([]*EthLogTrie, []cid.Cid, common.Hash, error) {
|
||||||
logTr := newLogTrie()
|
logTr := newLogTrie()
|
||||||
|
shortLogCIDs := make(map[uint64]cid.Cid, len(logs))
|
||||||
for idx, log := range logs {
|
for idx, log := range logs {
|
||||||
ethLog, err := NewLog(log)
|
logRaw, err := rlp.EncodeToBytes(log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, common.Hash{}, err
|
return nil, nil, common.Hash{}, err
|
||||||
}
|
}
|
||||||
if err = logTr.Add(idx, ethLog.RawData()); err != nil {
|
// if len(logRaw) <= keccak256Length it is possible this value's "leaf node"
|
||||||
|
// will be stored in its parent branch but only if len(partialPathOfTheNode) + len(logRaw) <= keccak256Length
|
||||||
|
// But we can't tell what the partial path will be until the trie is Commit()-ed
|
||||||
|
// So wait until we collect all the leaf nodes, and if we are missing any at the indexes we note in shortLogCIDs
|
||||||
|
// we know that these "leaf nodes" were internalized into their parent branch node and we move forward with
|
||||||
|
// using the cid.Cid we cached in shortLogCIDs
|
||||||
|
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
|
return nil, nil, common.Hash{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,7 +276,7 @@ func processLogs(logs []*types.Log) ([]*EthLogTrie, []cid.Cid, common.Hash, erro
|
|||||||
return nil, nil, common.Hash{}, err
|
return nil, nil, common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
leafNodeCids := make([]cid.Cid, len(leafNodes))
|
leafNodeCids := make([]cid.Cid, len(logs))
|
||||||
for i, ln := range leafNodes {
|
for i, ln := range leafNodes {
|
||||||
var idx uint
|
var idx uint
|
||||||
|
|
||||||
@ -271,6 +287,13 @@ func processLogs(logs []*types.Log) ([]*EthLogTrie, []cid.Cid, common.Hash, erro
|
|||||||
}
|
}
|
||||||
leafNodeCids[idx] = ln.Cid()
|
leafNodeCids[idx] = ln.Cid()
|
||||||
}
|
}
|
||||||
|
// this is where we check which logs <= keccak256Length were actually internalized into parent branch node
|
||||||
|
// and replace those that were with the cid.Cid for the raw log IPLD
|
||||||
|
for idx, lCID := range shortLogCIDs {
|
||||||
|
if !leafNodeCids[idx].Defined() {
|
||||||
|
leafNodeCids[idx] = lCID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return logTrieNodes, leafNodeCids, common.BytesToHash(logTr.rootHash()), err
|
return logTrieNodes, leafNodeCids, common.BytesToHash(logTr.rootHash()), err
|
||||||
}
|
}
|
||||||
|
@ -166,14 +166,8 @@ func (rt *rctTrie) getNodeFromDB(key []byte) (*EthRctTrie, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cid, err := RawdataToCid(MEthTxReceiptTrie, rawdata, multihash.KECCAK_256)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
tn := &TrieNode{
|
tn := &TrieNode{
|
||||||
cid: cid,
|
cid: keccak256ToCid(MEthTxReceiptTrie, key),
|
||||||
rawdata: rawdata,
|
rawdata: rawdata,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,12 +135,8 @@ func (tt *txTrie) getNodes() ([]*EthTxTrie, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c, err := RawdataToCid(MEthTxTrie, rawdata, multihash.KECCAK_256)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
tn := &TrieNode{
|
tn := &TrieNode{
|
||||||
cid: c,
|
cid: keccak256ToCid(MEthTxTrie, k),
|
||||||
rawdata: rawdata,
|
rawdata: rawdata,
|
||||||
}
|
}
|
||||||
out = append(out, &EthTxTrie{TrieNode: tn})
|
out = append(out, &EthTxTrie{TrieNode: tn})
|
||||||
|
Loading…
Reference in New Issue
Block a user