Skip to content

Commit 79617ee

Browse files
committed
triedb/pathdb: update comment
1 parent 8f9c277 commit 79617ee

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

triedb/pathdb/lookup.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,30 @@ func newLookup(head layer, descendant func(state common.Hash, ancestor common.Ha
8383
// layer specified by the stateID: fallback to the disk layer for data retrieval,
8484
// (b) or the layer specified by the stateID is stale: reject the data retrieval.
8585
func (l *lookup) accountTip(accountHash common.Hash, stateID common.Hash, base common.Hash) common.Hash {
86+
// Traverse the mutation history from latest to oldest one. Several
87+
// scenarios are possible:
88+
//
89+
// Chain:
90+
// D->C1->C2->C3->C4 (HEAD)
91+
// ->C1'->C2'->C3'
92+
// State:
93+
// x: [C1, C1', C3', C3]
94+
// y: []
95+
//
96+
// - (x, C4) => C3
97+
// - (x, C3) => C3
98+
// - (x, C2) => C1
99+
// - (x, C3') => C3'
100+
// - (x, C2') => C1'
101+
// - (y, C4) => D
102+
// - (y, C3') => D
103+
// - (y, C0) => null
86104
list := l.accounts[accountHash]
87105
for i := len(list) - 1; i >= 0; i-- {
106+
// If the current state matches the stateID, or the requested state is a
107+
// descendant of it, return the current state as the most recent one
108+
// containing the modified data. Otherwise, the current state may be ahead
109+
// of the requested one or belong to a different branch.
88110
if list[i] == stateID || l.descendant(stateID, list[i]) {
89111
return list[i]
90112
}
@@ -115,6 +137,10 @@ func (l *lookup) storageTip(accountHash common.Hash, slotHash common.Hash, state
115137
if exists {
116138
list := subset[slotHash]
117139
for i := len(list) - 1; i >= 0; i-- {
140+
// If the current state matches the stateID, or the requested state is a
141+
// descendant of it, return the current state as the most recent one
142+
// containing the modified data. Otherwise, the current state may be ahead
143+
// of the requested one or belong to a different branch.
118144
if list[i] == stateID || l.descendant(stateID, list[i]) {
119145
return list[i]
120146
}

0 commit comments

Comments
 (0)