-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run consensus with several validators
Right now it's implemented as a test.
- Loading branch information
Showing
9 changed files
with
170 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ibft | ||
|
||
import ( | ||
"github.com/NilFoundation/nil/nil/internal/config" | ||
) | ||
|
||
func (i *backendIBFT) calcProposer(height, round uint64) config.ValidatorInfo { | ||
index := (height + round) % uint64(len(i.validators)) | ||
return i.validators[index] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/NilFoundation/nil/nil/internal/types" | ||
"github.com/NilFoundation/nil/nil/services/nilservice" | ||
"github.com/NilFoundation/nil/nil/tests" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type SuiteConsensus struct { | ||
tests.ShardedSuite | ||
} | ||
|
||
func (s *SuiteConsensus) SetupTest() { | ||
nShards := uint32(3) | ||
|
||
s.StartShardAllValidators(&nilservice.Config{ | ||
NShards: nShards, | ||
CollatorTickPeriodMs: 200, | ||
}, 10625) | ||
} | ||
|
||
func (s *SuiteConsensus) TearDownTest() { | ||
s.Cancel() | ||
} | ||
|
||
func (s *SuiteConsensus) TestConsensus() { | ||
for shardId, shard := range s.Shards { | ||
block, err := shard.Client.GetBlock(s.Context, types.ShardId(shardId), "latest", true) | ||
s.Require().NoError(err) | ||
|
||
s.Require().Eventually(func() bool { | ||
newBlock, err := shard.Client.GetBlock(s.Context, types.ShardId(shardId), "latest", true) | ||
s.Require().NoError(err) | ||
return newBlock != nil && newBlock.Number > block.Number | ||
}, 20*time.Second, 1*time.Second) | ||
} | ||
} | ||
|
||
func TestConsensus(t *testing.T) { | ||
t.Parallel() | ||
|
||
suite.Run(t, new(SuiteConsensus)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters