Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mtrie with some minor fixes and small improvements #1801

Merged
merged 8 commits into from
Jan 13, 2022
Prev Previous commit
Next Next commit
Remove unnecessary error conversion in Ledger.Set
In Ledger.Set(), PSMT.Update() returns error of type
ledger.ErrMissingKeys.

We don't need to convert error from ptrie.ErrMissingPath type because
ledger.ErrMissingKeys type is being returned.
fxamacker committed Jan 4, 2022
commit f93cb56b2ccc290d22e8fa1f656b9ce837fe7ef0
22 changes: 1 addition & 21 deletions ledger/partial/ledger.go
Original file line number Diff line number Diff line change
@@ -113,27 +113,7 @@ func (l *Ledger) Set(update *ledger.Update) (newState ledger.State, trieUpdate *

newRootHash, err := l.ptrie.Update(trieUpdate.Paths, trieUpdate.Payloads)
if err != nil {
if pErr, ok := err.(*ptrie.ErrMissingPath); ok {

paths, err := pathfinder.KeysToPaths(update.Keys(), l.pathFinderVersion)
if err != nil {
return ledger.DummyState, nil, err
}

//store mappings and restore keys from missing paths
pathToKey := make(map[ledger.Path]ledger.Key)

for i, key := range update.Keys() {
path := paths[i]
pathToKey[path] = key
}

keys := make([]ledger.Key, 0, len(pErr.Paths))
for _, path := range pErr.Paths {
keys = append(keys, pathToKey[path])
}
return ledger.DummyState, nil, &ledger.ErrMissingKeys{Keys: keys}
}
// Returned error type is ledger.ErrMissingKeys
return ledger.DummyState, nil, err
}