Skip to content

Commit

Permalink
Merge branch 'master' into abi-encoding-decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
franklywatson authored Dec 12, 2023
2 parents 190df1a + 2088ac5 commit fbe3d07
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ledger/common/pathfinder/pathfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func PayloadsToValues(payloads []*ledger.Payload) ([]ledger.Value, error) {
}

// PathsFromPayloads constructs paths from an slice of payload
func PathsFromPayloads(payloads []ledger.Payload, version uint8) ([]ledger.Path, error) {
func PathsFromPayloads(payloads []*ledger.Payload, version uint8) ([]ledger.Path, error) {
paths := make([]ledger.Path, len(payloads))
for i, pay := range payloads {
k, err := pay.Key()
Expand Down
9 changes: 7 additions & 2 deletions ledger/complete/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (l *Ledger) MigrateAt(
fmt.Errorf("failed to clean up tries to reduce memory usage: %w", err)
}

var payloads []ledger.Payload
var payloads []*ledger.Payload
var newTrie *trie.MTrie

noMigration := len(migrations) == 0
Expand Down Expand Up @@ -413,9 +413,14 @@ func (l *Ledger) MigrateAt(

emptyTrie := trie.NewEmptyMTrie()

derefPayloads := make([]ledger.Payload, len(payloads))
for i, p := range payloads {
derefPayloads[i] = *p
}

// no need to prune the data since it has already been prunned through migrations
applyPruning := false
newTrie, _, err = trie.NewTrieWithUpdatedRegisters(emptyTrie, paths, payloads, applyPruning)
newTrie, _, err = trie.NewTrieWithUpdatedRegisters(emptyTrie, paths, derefPayloads, applyPruning)
if err != nil {
return nil, fmt.Errorf("constructing updated trie failed: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions ledger/complete/mtrie/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ func (n *Node) FmtStr(prefix string, subpath string) string {
}

// AllPayloads returns the payload of this node and all payloads of the subtrie
func (n *Node) AllPayloads() []ledger.Payload {
return n.appendSubtreePayloads([]ledger.Payload{})
func (n *Node) AllPayloads() []*ledger.Payload {
return n.appendSubtreePayloads([]*ledger.Payload{})
}

// appendSubtreePayloads appends the payloads of the subtree with this node as root
// to the provided Payload slice. Follows same pattern as Go's native append method.
func (n *Node) appendSubtreePayloads(result []ledger.Payload) []ledger.Payload {
func (n *Node) appendSubtreePayloads(result []*ledger.Payload) []*ledger.Payload {
if n == nil {
return result
}
if n.IsLeaf() {
return append(result, *n.Payload())
return append(result, n.Payload())
}
result = n.lChild.appendSubtreePayloads(result)
result = n.rChild.appendSubtreePayloads(result)
Expand Down
2 changes: 1 addition & 1 deletion ledger/complete/mtrie/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ func EmptyTrieRootHash() ledger.RootHash {
}

// AllPayloads returns all payloads
func (mt *MTrie) AllPayloads() []ledger.Payload {
func (mt *MTrie) AllPayloads() []*ledger.Payload {
return mt.root.AllPayloads()
}

Expand Down
4 changes: 2 additions & 2 deletions ledger/complete/wal/checkpoint_v6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,11 @@ func TestWriteAndReadCheckpointV6LeafSimpleTrie(t *testing.T) {
err := OpenAndReadLeafNodesFromCheckpointV6(leafNodesCh, dir, fileName, logger)
require.NoErrorf(t, err, "fail to read checkpoint %v/%v", dir, fileName)
}()
resultPayloads := make([]ledger.Payload, 0)
resultPayloads := make([]*ledger.Payload, 0)
for leafNode := range leafNodesCh {
// avoid dummy payload from empty trie
if leafNode.Payload != nil {
resultPayloads = append(resultPayloads, *leafNode.Payload)
resultPayloads = append(resultPayloads, leafNode.Payload)
}
}
require.EqualValues(t, tries[1].AllPayloads(), resultPayloads)
Expand Down
2 changes: 1 addition & 1 deletion ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (v *Value) UnmarshalJSON(b []byte) error {
}

// Migration defines how to convert the given slice of input payloads into an slice of output payloads
type Migration func(payloads []Payload) ([]Payload, error)
type Migration func(payloads []*Payload) ([]*Payload, error)

// Reporter reports on data from the state
type Reporter interface {
Expand Down
12 changes: 6 additions & 6 deletions ledger/mock/migration.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fbe3d07

Please sign in to comment.