Skip to content

Commit

Permalink
revise interfaces, update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Oct 11, 2024
1 parent 76f21a5 commit 972b91a
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 157 deletions.
2 changes: 1 addition & 1 deletion internal/client/consensus/grandpa/finality_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func proveFinality[
block)
return nil, nil //nolint
}
justification := justifications.IntoJustification(primitives.GrandpaEngineID)
justification := justifications.EncodedJustification(primitives.GrandpaEngineID)
if justification != nil {
encJustification = *justification
justBlock = val.inner.BlockNumber
Expand Down
2 changes: 1 addition & 1 deletion internal/client/consensus/grandpa/finality_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestFinalityProof_UsingAuthoritySetChangesWorks(t *testing.T) {
ConsensusEngineID: primitives.GrandpaEngineID,
EncodedJustification: scale.MustMarshal(grandpaJust8),
}
blockchainBackend.EXPECT().Justifications(block8.Hash()).Return(&runtime.Justifications{justification}, nil)
blockchainBackend.EXPECT().Justifications(block8.Hash()).Return(runtime.Justifications{justification}, nil)

blockchainBackend.EXPECT().ExpectBlockHashFromID(uint64(7)).Return(block7.Hash(), nil)
blockchainBackend.EXPECT().ExpectHeader(block7.Hash()).Return(block7.Header(), nil)
Expand Down
2 changes: 1 addition & 1 deletion internal/client/consensus/grandpa/justification.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func NewJustificationFromCommit[
fmt.Errorf("%w: invalid precommits for target commit", errBadJustification)
}

currentHeader := *header
currentHeader := header

// NOTE: this should never happen as we pick the lowest block
// as base and only traverse backwards from the other blocks
Expand Down
4 changes: 2 additions & 2 deletions internal/client/consensus/grandpa/justification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestJustification_fromCommit(t *testing.T) {
"",
runtime.Digest{})

client.EXPECT().Header(hash.H256("b")).Return(&header, nil)
client.EXPECT().Header(hash.H256("b")).Return(header, nil)
_, err = NewJustificationFromCommit[hash.H256, uint64](
client,
2,
Expand All @@ -142,7 +142,7 @@ func TestJustification_fromCommit(t *testing.T) {
runtime.Digest{})

client = mocks.NewHeaderBackend[hash.H256, uint64](t)
client.EXPECT().Header(hash.H256("b")).Return(&header, nil)
client.EXPECT().Header(hash.H256("b")).Return(header, nil)

expAncestries := make([]runtime.Header[uint64, hash.H256], 0)
expAncestries = append(expAncestries, generic.NewHeader[uint64, hash.H256, runtime.BlakeTwo256](
Expand Down
70 changes: 35 additions & 35 deletions internal/client/consensus/grandpa/mocks/blockchain_backend.go

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

14 changes: 7 additions & 7 deletions internal/client/consensus/grandpa/mocks/header_backend.go

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

35 changes: 17 additions & 18 deletions internal/primitives/blockchain/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import (
"github.com/ChainSafe/gossamer/internal/primitives/runtime/generic"
)

// Blockchain database header backend. Does not perform any validation.
// Header is the blockchain database header backend. Does not perform any validation.
type HeaderBackend[Hash runtime.Hash, N runtime.Number] interface {
// Get block header. Returns `None` if block is not found.
Header(hash Hash) (*runtime.Header[N, Hash], error)
// Get block header. Returns `nil` if block is not found.
Header(hash Hash) (runtime.Header[N, Hash], error)

// Get blockchain info.
Info() Info[Hash, N]

// Get block status.
Status(hash Hash) (BlockStatus, error)

// Get block number by hash. Returns `None` if the header is not in the chain.
// Get block number by hash. Returns `nil` if the header is not in the chain.
Number(hash Hash) (*N, error)

// Get block hash by number. Returns `None` if the header is not in the chain.
// Get block hash by number. Returns `nil` if the header is not in the chain.
Hash(number N) (*Hash, error)

// Convert an arbitrary block ID into a block hash.
Expand All @@ -48,12 +48,12 @@ type HeaderBackend[Hash runtime.Hash, N runtime.Number] interface {
// Blockchain database backend. Does not perform any validation.
type Backend[Hash runtime.Hash, N runtime.Number] interface {
HeaderBackend[Hash, N]
// HeaderMetaData[Hash, N]
// HeaderMetadata[Hash, N]

// Get block body. Returns `None` if block is not found.
Body(hash Hash) (*[]runtime.Extrinsic, error)
// Get block justifications. Returns `None` if no justification exists.
Justifications(hash Hash) (*runtime.Justifications, error)
// Get block body. Returns `nil` if block is not found.
Body(hash Hash) ([]runtime.Extrinsic, error)
// Get block justifications. Returns `nil` if no justification exists.
Justifications(hash Hash) (runtime.Justifications, error)
// Get last finalized block hash.
LastFinalized() (Hash, error)

Expand All @@ -64,30 +64,29 @@ type Backend[Hash runtime.Hash, N runtime.Number] interface {

// Returns displaced leaves after the given block would be finalized.
//
// The returned leaves do not contain the leaves from the same height as `block_number`.
// The returned leaves do not contain the leaves from the same height as `blockNumber`.
DisplacedLeavesAfterFinalizing(blockNumber N) ([]Hash, error)

// Return hashes of all blocks that are children of the block with `parent_hash`.
// Return hashes of all blocks that are children of the block with `parentHash`.
Children(parentHash Hash) ([]Hash, error)

// Get the most recent block hash of the longest chain that contains
// a block with the given `base_hash`.
// a block with the given `baseHash`.
//
// The search space is always limited to blocks which are in the finalized
// chain or descendents of it.
//
// Returns `Ok(None)` if `base_hash` is not found in search space.
// TODO: document time complexity of this, see [#1444](https://github.com/paritytech/substrate/issues/1444)
// Returns `nil` if `basehash` is not found in search space.
LongestContaining(baseHash Hash, importLock *sync.RWMutex) (*Hash, error)

// Get single indexed transaction by content hash. Note that this will only fetch transactions
// that are indexed by the runtime with `storage_index_transaction`.
IndexedTransaction(hash Hash) (*[]byte, error)
IndexedTransaction(hash Hash) ([]byte, error)

// Check if indexed transaction exists.
HasIndexedTransaction(hash Hash) (bool, error)

BlockIndexedBody(hash Hash) (*[][]byte, error)
BlockIndexedBody(hash Hash) ([][]byte, error)
}

// Blockchain info
Expand All @@ -113,7 +112,7 @@ type Info[H, N any] struct {
BlockGap *[2]N
}

// Block status.
// BlockStatus is block status.
type BlockStatus uint

const (
Expand Down
Loading

0 comments on commit 972b91a

Please sign in to comment.