@@ -248,6 +248,12 @@ func processLogs(logs []*types.Log) ([]*EthLogTrie, []cid.Cid, common.Hash, erro
248248 if err != nil {
249249 return nil , nil , common.Hash {}, err
250250 }
251+ // if len(logRaw) <= keccak256Length it is possible this value's "leaf node"
252+ // will be stored in its parent branch but only if len(partialPathOfTheNode) + len(logRaw) <= keccak256Length
253+ // But we can't tell what the partial path will be until the trie is Commit()-ed
254+ // So wait until we collect all the leaf nodes, and if we are missing any at the indexes we note in shortLogCIDs
255+ // we know that these "leaf nodes" were internalized into their parent branch node and we move forward with
256+ // using the cid.Cid we cached in shortLogCIDs
251257 if len (logRaw ) <= keccak256Length {
252258 logNode , err := NewLog (log )
253259 if err != nil {
@@ -280,8 +286,12 @@ func processLogs(logs []*types.Log) ([]*EthLogTrie, []cid.Cid, common.Hash, erro
280286 }
281287 leafNodeCids [idx ] = ln .Cid ()
282288 }
289+ // this is where we check which logs <= keccak256Length were actually internalized into parent branch node
290+ // and replace those that were with the cid.Cid for the raw log IPLD
283291 for idx , lCID := range shortLogCIDs {
284- leafNodeCids [idx ] = lCID
292+ if ! leafNodeCids [idx ].Defined () {
293+ leafNodeCids [idx ] = lCID
294+ }
285295 }
286296
287297 return logTrieNodes , leafNodeCids , common .BytesToHash (logTr .rootHash ()), err
0 commit comments