Skip to content

Commit

Permalink
Merge branch 'development' into trie-hybrid-state
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Feb 7, 2024
2 parents 0069a00 + d1ca7aa commit c88b51f
Show file tree
Hide file tree
Showing 94 changed files with 2,390 additions and 2,119 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- name: Generate coverage report
run: |
go test ./... -coverprofile=coverage.out -covermode=atomic -timeout=20m
- uses: codecov/codecov-action@v3.1.4
- uses: codecov/codecov-action@v3.1.5
with:
files: ./coverage.out
flags: unit-tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/copyright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-grandpa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
DOCKER_BUILDKIT: "1"
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
DOCKER_BUILDKIT: "1"
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
DOCKER_BUILDKIT: "1"
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-stress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
DOCKER_BUILDKIT: "1"
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
uses: styfle/cancel-workflow-action@0.12.1
with:
all_but_latest: true

Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Test - Race
run: make test-using-race-detector

- uses: codecov/codecov-action@v3.1.4
- uses: codecov/codecov-action@v3.1.5
with:
if_ci_failed: success
informational: true
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ tmp
# node_modules used by polkadot.js/api tests
tests/polkadotjs_test/node_modules
!tests/polkadotjs_test/test/*.wasm

*.json
2 changes: 1 addition & 1 deletion dot/core/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestServiceHandleTransactionMessage(t *testing.T) {
runtimeMock3 := NewMockInstance(ctrl)

invalidTransaction := runtime.NewInvalidTransaction()
err := invalidTransaction.Set(runtime.Future{})
err := invalidTransaction.SetValue(runtime.Future{})
require.NoError(t, err)

type args struct {
Expand Down
6 changes: 3 additions & 3 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ func (s *Service) HandleBlockProduced(block *types.Block, state *rtstorage.TrieS
func createBlockAnnounce(block *types.Block, isBestBlock bool) (
blockAnnounce *network.BlockAnnounceMessage, err error) {
digest := types.NewDigest()
for i := range block.Header.Digest.Types {
digestValue, err := block.Header.Digest.Types[i].Value()
for i := range block.Header.Digest {
digestValue, err := block.Header.Digest[i].Value()
if err != nil {
return nil, fmt.Errorf("getting value of digest type at index %d: %w", i, err)
}
Expand All @@ -217,7 +217,7 @@ func (s *Service) handleBlock(block *types.Block, state *rtstorage.TrieState) er
return ErrNilBlockHandlerParameter
}

//store updates state trie nodes in database
// store updates state trie nodes in database
err := s.storageState.StoreTrie(state, &block.Header)
if err != nil {
logger.Warnf("failed to store state trie for imported block %s: %s",
Expand Down
4 changes: 2 additions & 2 deletions dot/digest/block_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewBlockImportHandler(epochState EpochState, grandpaState GrandpaState) *Bl

// HandleDigests handles consensus digests for an imported block
func (h *BlockImportHandler) HandleDigests(header *types.Header) error {
consensusDigests := toConsensusDigests(header.Digest.Types)
consensusDigests := toConsensusDigests(header.Digest)
consensusDigests, err := checkForGRANDPAForcedChanges(consensusDigests)
if err != nil {
return fmt.Errorf("failed while checking GRANDPA digests: %w", err)
Expand Down Expand Up @@ -76,7 +76,7 @@ func (h *BlockImportHandler) handleConsensusDigest(d *types.ConsensusDigest, hea
}

// toConsensusDigests converts a slice of scale.VaryingDataType to a slice of types.ConsensusDigest.
func toConsensusDigests(scaleVaryingTypes []scale.VaryingDataType) []types.ConsensusDigest {
func toConsensusDigests(scaleVaryingTypes types.Digest) []types.ConsensusDigest {
consensusDigests := make([]types.ConsensusDigest, 0, len(scaleVaryingTypes))

for _, d := range scaleVaryingTypes {
Expand Down
14 changes: 7 additions & 7 deletions dot/digest/block_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestBlockImportHandle(t *testing.T) {
})

versionedNextConfigData := types.NewVersionedNextConfigData()
versionedNextConfigData.Set(types.NextConfigDataV1{
versionedNextConfigData.SetValue(types.NextConfigDataV1{
C1: 9,
C2: 10,
SecondarySlots: 1,
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestBlockImportHandle(t *testing.T) {
}

versionedNextConfigData := types.NewVersionedNextConfigData()
versionedNextConfigData.Set(types.NextConfigDataV1{
versionedNextConfigData.SetValue(types.NextConfigDataV1{
C1: 9,
C2: 10,
SecondarySlots: 1,
Expand Down Expand Up @@ -288,11 +288,11 @@ func TestBlockImportHandle(t *testing.T) {
}
}

func createBABEConsensusDigest(t *testing.T, digestData scale.VaryingDataTypeValue) types.ConsensusDigest {
func createBABEConsensusDigest(t *testing.T, digestData any) types.ConsensusDigest {
t.Helper()

babeConsensusDigest := types.NewBabeConsensusDigest()
require.NoError(t, babeConsensusDigest.Set(digestData))
require.NoError(t, babeConsensusDigest.SetValue(digestData))

marshaledData, err := scale.Marshal(babeConsensusDigest)
require.NoError(t, err)
Expand All @@ -303,11 +303,11 @@ func createBABEConsensusDigest(t *testing.T, digestData scale.VaryingDataTypeVal
}
}

func createGRANDPAConsensusDigest(t *testing.T, digestData scale.VaryingDataTypeValue) types.ConsensusDigest {
func createGRANDPAConsensusDigest(t *testing.T, digestData any) types.ConsensusDigest {
t.Helper()

grandpaConsensusDigest := types.NewGrandpaConsensusDigest()
require.NoError(t, grandpaConsensusDigest.Set(digestData))
require.NoError(t, grandpaConsensusDigest.SetValue(digestData))

marshaledData, err := scale.Marshal(grandpaConsensusDigest)
require.NoError(t, err)
Expand All @@ -323,7 +323,7 @@ func createBlockWithDigests(t *testing.T, genesisHeader *types.Header, digestsTo
t.Helper()

digest := types.NewDigest()
digestAddArgs := make([]scale.VaryingDataTypeValue, len(digestsToApply))
digestAddArgs := make([]any, len(digestsToApply))

for idx, consensusDigest := range digestsToApply {
digestAddArgs[idx] = consensusDigest
Expand Down
36 changes: 18 additions & 18 deletions dot/digest/digest_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestHandler_GrandpaScheduledChange(t *testing.T) {
}

var digest = types.NewGrandpaConsensusDigest()
err = digest.Set(sc)
err = digest.SetValue(sc)
require.NoError(t, err)

data, err := scale.Marshal(digest)
Expand Down Expand Up @@ -110,48 +110,48 @@ func TestHandler_GrandpaScheduledChange(t *testing.T) {

func TestMultipleGRANDPADigests_ShouldIncludeJustForcedChanges(t *testing.T) {
tests := map[string]struct {
digestsTypes []scale.VaryingDataTypeValue
expectedHandled []scale.VaryingDataTypeValue
digestsTypes []any
expectedHandled []any
}{
"forced_and_scheduled_changes_same_block": {
digestsTypes: []scale.VaryingDataTypeValue{
digestsTypes: []any{
types.GrandpaForcedChange{},
types.GrandpaScheduledChange{},
},
expectedHandled: []scale.VaryingDataTypeValue{
expectedHandled: []any{
types.GrandpaForcedChange{},
},
},
"only_scheduled_change_in_block": {
digestsTypes: []scale.VaryingDataTypeValue{
digestsTypes: []any{
types.GrandpaScheduledChange{},
},
expectedHandled: []scale.VaryingDataTypeValue{
expectedHandled: []any{
types.GrandpaScheduledChange{},
},
},
"more_than_one_forced_changes_in_block": {
digestsTypes: []scale.VaryingDataTypeValue{
digestsTypes: []any{
types.GrandpaForcedChange{},
types.GrandpaForcedChange{},
types.GrandpaForcedChange{},
types.GrandpaScheduledChange{},
},
expectedHandled: []scale.VaryingDataTypeValue{
expectedHandled: []any{
types.GrandpaForcedChange{},
types.GrandpaForcedChange{},
types.GrandpaForcedChange{},
},
},
"multiple_consensus_digests_in_block": {
digestsTypes: []scale.VaryingDataTypeValue{
digestsTypes: []any{
types.GrandpaOnDisabled{},
types.GrandpaPause{},
types.GrandpaResume{},
types.GrandpaForcedChange{},
types.GrandpaScheduledChange{},
},
expectedHandled: []scale.VaryingDataTypeValue{
expectedHandled: []any{
types.GrandpaOnDisabled{},
types.GrandpaPause{},
types.GrandpaResume{},
Expand All @@ -167,7 +167,7 @@ func TestMultipleGRANDPADigests_ShouldIncludeJustForcedChanges(t *testing.T) {

for _, item := range tt.digestsTypes {
var digest = types.NewGrandpaConsensusDigest()
require.NoError(t, digest.Set(item))
require.NoError(t, digest.SetValue(item))

data, err := scale.Marshal(digest)
require.NoError(t, err)
Expand All @@ -190,7 +190,7 @@ func TestMultipleGRANDPADigests_ShouldIncludeJustForcedChanges(t *testing.T) {

for _, item := range tt.expectedHandled {
var digest = types.NewGrandpaConsensusDigest()
require.NoError(t, digest.Set(item))
require.NoError(t, digest.SetValue(item))

data, err := scale.Marshal(digest)
require.NoError(t, err)
Expand All @@ -215,7 +215,7 @@ func TestHandler_HandleBABEOnDisabled(t *testing.T) {
}

var digest = types.NewBabeConsensusDigest()
err := digest.Set(types.BABEOnDisabled{
err := digest.SetValue(types.BABEOnDisabled{
ID: 7,
})
require.NoError(t, err)
Expand All @@ -236,7 +236,7 @@ func createHeaderWithPreDigest(t *testing.T, slotNumber uint64) *types.Header {
t.Helper()

babeHeader := types.NewBabeDigest()
err := babeHeader.Set(*types.NewBabePrimaryPreDigest(0, slotNumber, [32]byte{}, [64]byte{}))
err := babeHeader.SetValue(*types.NewBabePrimaryPreDigest(0, slotNumber, [32]byte{}, [64]byte{}))
require.NoError(t, err)

enc, err := scale.Marshal(babeHeader)
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestHandler_HandleNextEpochData(t *testing.T) {
}

digest := types.NewBabeConsensusDigest()
err = digest.Set(nextEpochData)
err = digest.SetValue(nextEpochData)
require.NoError(t, err)

data, err := scale.Marshal(digest)
Expand Down Expand Up @@ -339,9 +339,9 @@ func TestHandler_HandleNextConfigData(t *testing.T) {
}

versionedNextConfigData := types.NewVersionedNextConfigData()
versionedNextConfigData.Set(nextConfigData)
versionedNextConfigData.SetValue(nextConfigData)

err := digest.Set(versionedNextConfigData)
err := digest.SetValue(versionedNextConfigData)
require.NoError(t, err)

data, err := scale.Marshal(digest)
Expand Down
5 changes: 2 additions & 3 deletions dot/digest/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/pkg/scale"
)

// BlockState interface for block state methods
Expand All @@ -21,14 +20,14 @@ type BlockState interface {
// EpochState is the interface for state.EpochState
type EpochState interface {
GetEpochForBlock(header *types.Header) (uint64, error)
HandleBABEDigest(header *types.Header, digest scale.VaryingDataType) error
HandleBABEDigest(header *types.Header, digest types.BabeConsensusDigest) error
FinalizeBABENextEpochData(finalizedHeader *types.Header) error
FinalizeBABENextConfigData(finalizedHeader *types.Header) error
}

// GrandpaState is the interface for the state.GrandpaState
type GrandpaState interface {
HandleGRANDPADigest(header *types.Header, digest scale.VaryingDataType) error
HandleGRANDPADigest(header *types.Header, digest types.GrandpaConsensusDigest) error
ApplyScheduledChanges(finalizedHeader *types.Header) error
}

Expand Down
3 changes: 1 addition & 2 deletions dot/digest/mock_epoch_state_test.go

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

Loading

0 comments on commit c88b51f

Please sign in to comment.