Skip to content

Commit

Permalink
refactor(pkg/trie): Remove GenesisBlock method from tries (#3844)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro authored Apr 3, 2024
1 parent df4ac1c commit a8754b8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 105 deletions.
2 changes: 1 addition & 1 deletion dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (nodeBuilder) initNode(config *cfg.Config) error {
}

// create genesis block from trie
header, err := t.GenesisBlock()
header, err := runtime.GenesisBlockFromTrie(t)
if err != nil {
return fmt.Errorf("failed to create genesis block from trie: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion dot/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestNewNode(t *testing.T) {
return nil, fmt.Errorf("failed to create trie from genesis: %w", err)
}
// create genesis block from trie
header, err := trie.GenesisBlock()
header, err := runtime.GenesisBlockFromTrie(trie)
if err != nil {
return nil, fmt.Errorf("failed to create genesis block from trie: %w", err)
}
Expand Down
16 changes: 16 additions & 0 deletions lib/runtime/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"errors"
"fmt"

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/pkg/trie"
in_memory_trie "github.com/ChainSafe/gossamer/pkg/trie/inmemory"
Expand All @@ -33,3 +35,17 @@ func NewTrieFromGenesis(gen genesis.Genesis) (tr trie.Trie, err error) {

return tr, nil
}

func GenesisBlockFromTrie(t trie.Trie) (genesisHeader types.Header, err error) {
rootHash, err := t.Hash()
if err != nil {
return genesisHeader, fmt.Errorf("root hashing trie: %w", err)
}

parentHash := common.Hash{0}
extrinsicRoot := trie.EmptyHash
const blockNumber = 0
digest := types.NewDigest()
genesisHeader = *types.NewHeader(parentHash, rootHash, extrinsicRoot, blockNumber, digest)
return genesisHeader, nil
}
27 changes: 0 additions & 27 deletions pkg/trie/inmemory/genesis.go

This file was deleted.

74 changes: 0 additions & 74 deletions pkg/trie/inmemory/genesis_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package trie
import (
"fmt"

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/trie/tracking"
)
Expand Down Expand Up @@ -53,7 +52,6 @@ type Versioned interface {
type Hashable interface {
MustHash() common.Hash
Hash() (common.Hash, error)
GenesisBlock() (genesisHeader types.Header, err error)
}

type Trie interface {
Expand Down

0 comments on commit a8754b8

Please sign in to comment.