Skip to content

Commit

Permalink
Merge pull request #263 from ElrondNetwork/issue/#248-Wrong-nonce-in-…
Browse files Browse the repository at this point in the history
…block

Issue/#248 wrong nonce in block
  • Loading branch information
iulianpascalau committed Jul 10, 2019
2 parents f74d34d + 80441cf commit bd54836
Show file tree
Hide file tree
Showing 36 changed files with 1,372 additions and 1,112 deletions.
28 changes: 14 additions & 14 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ VERSION:
Usage: "The file containing the secret keys which ...",
Value: "./config/initialNodesSk.pem",
}
// boostrapRoundIndex defines a flag that specifies the round index from which node should bootstrap from storage
boostrapRoundIndex = cli.UintFlag{
Name: "boostrap-round-index",
Usage: "Boostrap round index specifies the round index from which node should bootstrap from storage",
// bootstrapRoundIndex defines a flag that specifies the round index from which node should bootstrap from storage
bootstrapRoundIndex = cli.UintFlag{
Name: "bootstrap-round-index",
Usage: "Bootstrap round index specifies the round index from which node should bootstrap from storage",
Value: math.MaxUint32,
}

Expand Down Expand Up @@ -212,7 +212,7 @@ func main() {
app := cli.NewApp()
cli.AppHelpTemplate = nodeHelpTemplate
app.Name = "Elrond Node CLI App"
app.Version = "v1.0.4"
app.Version = "v1.0.8"
app.Usage = "This is the entry point for starting a new Elrond node - the app will start after the genesis timestamp"
app.Flags = []cli.Flag{
genesisFile,
Expand All @@ -232,7 +232,7 @@ func main() {
gopsEn,
serversConfigurationFile,
restApiPort,
boostrapRoundIndex,
bootstrapRoundIndex,
workingDirectory,
}
app.Authors = []cli.Author{
Expand All @@ -247,7 +247,7 @@ func main() {
debug.SetMaxThreads(100000)

app.Action = func(c *cli.Context) error {
return startNode(c, log)
return startNode(c, log, app.Version)
}

err := app.Run(os.Args)
Expand All @@ -268,7 +268,7 @@ func getSuite(config *config.Config) (crypto.Suite, error) {
return nil, errors.New("no consensus provided in config file")
}

func startNode(ctx *cli.Context, log *logger.Logger) error {
func startNode(ctx *cli.Context, log *logger.Logger, version string) error {
profileMode := ctx.GlobalString(profileMode.Name)
switch profileMode {
case "cpu":
Expand All @@ -287,12 +287,12 @@ func startNode(ctx *cli.Context, log *logger.Logger) error {

enableGopsIfNeeded(ctx, log)

log.Info("Starting node...")

stop := make(chan bool, 1)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

log.Info(fmt.Sprintf("Starting node with version %s\n", version))

configurationFileName := ctx.GlobalString(configurationFile.Name)
generalConfig, err := loadMainConfig(configurationFileName, log)
if err != nil {
Expand Down Expand Up @@ -396,7 +396,7 @@ func startNode(ctx *cli.Context, log *logger.Logger) error {
"PublicKey", factory.GetPkEncoded(pubKey),
"ShardId", shardId,
"TotalShards", shardCoordinator.NumberOfShards(),
"AppVersion", "TestVersion",
"AppVersion", version,
"OsVersion", "TestOs",
)

Expand Down Expand Up @@ -490,7 +490,7 @@ func startNode(ctx *cli.Context, log *logger.Logger) error {
cryptoComponents,
processComponents,
networkComponents,
uint32(ctx.GlobalUint(boostrapRoundIndex.Name)),
uint32(ctx.GlobalUint(bootstrapRoundIndex.Name)),
)
if err != nil {
return err
Expand Down Expand Up @@ -680,7 +680,7 @@ func createNode(
crypto *factory.Crypto,
process *factory.Process,
network *factory.Network,
boostrapRoundIndex uint32,
bootstrapRoundIndex uint32,
) (*node.Node, error) {
consensusGroupSize, err := getConsensusGroupSize(nodesConfig, shardCoordinator)
if err != nil {
Expand Down Expand Up @@ -718,7 +718,7 @@ func createNode(
node.WithConsensusType(config.Consensus.Type),
node.WithTxSingleSigner(crypto.TxSingleSigner),
node.WithTxStorageSize(config.TxStorage.Cache.Size),
node.WithBoostrapRoundIndex(boostrapRoundIndex),
node.WithBootstrapRoundIndex(bootstrapRoundIndex),
)
if err != nil {
return nil, errors.New("error creating node: " + err.Error())
Expand Down
14 changes: 7 additions & 7 deletions consensus/mock/bootstrapMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"github.com/ElrondNetwork/elrond-go/data/block"
)

// BootstraperMock mocks the implementation for a Bootstraper
type BootstraperMock struct {
// BootstrapperMock mocks the implementation for a Bootstrapper
type BootstrapperMock struct {
CreateAndCommitEmptyBlockCalled func(uint32) (data.BodyHandler, data.HeaderHandler, error)
AddSyncStateListenerCalled func(func(bool))
ShouldSyncCalled func() bool
StartSyncCalled func()
StopSyncCalled func()
}

func (boot *BootstraperMock) CreateAndCommitEmptyBlock(shardForCurrentNode uint32) (data.BodyHandler, data.HeaderHandler, error) {
func (boot *BootstrapperMock) CreateAndCommitEmptyBlock(shardForCurrentNode uint32) (data.BodyHandler, data.HeaderHandler, error) {
if boot.CreateAndCommitEmptyBlockCalled != nil {
return boot.CreateAndCommitEmptyBlockCalled(shardForCurrentNode)
}
Expand All @@ -23,7 +23,7 @@ func (boot *BootstraperMock) CreateAndCommitEmptyBlock(shardForCurrentNode uint3
return bb, &block.Header{}, nil
}

func (boot *BootstraperMock) AddSyncStateListener(syncStateNotifier func(bool)) {
func (boot *BootstrapperMock) AddSyncStateListener(syncStateNotifier func(bool)) {
if boot.AddSyncStateListenerCalled != nil {
boot.AddSyncStateListenerCalled(syncStateNotifier)
return
Expand All @@ -32,18 +32,18 @@ func (boot *BootstraperMock) AddSyncStateListener(syncStateNotifier func(bool))
return
}

func (boot *BootstraperMock) ShouldSync() bool {
func (boot *BootstrapperMock) ShouldSync() bool {
if boot.ShouldSyncCalled != nil {
return boot.ShouldSyncCalled()
}

return false
}

func (boot *BootstraperMock) StartSync() {
func (boot *BootstrapperMock) StartSync() {
boot.StartSyncCalled()
}

func (boot *BootstraperMock) StopSync() {
func (boot *BootstrapperMock) StopSync() {
boot.StopSyncCalled()
}
8 changes: 4 additions & 4 deletions consensus/mock/consensusDataContainerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ConsensusCoreMock struct {
blockChain data.ChainHandler
blockProcessor process.BlockProcessor
blocksTracker process.BlocksTracker
bootstraper process.Bootstrapper
bootstrapper process.Bootstrapper
broadcastMessenger consensus.BroadcastMessenger
chronologyHandler consensus.ChronologyHandler
hasher hashing.Hasher
Expand All @@ -42,7 +42,7 @@ func (cdc *ConsensusCoreMock) BlocksTracker() process.BlocksTracker {
}

func (cdc *ConsensusCoreMock) BootStrapper() process.Bootstrapper {
return cdc.bootstraper
return cdc.bootstrapper
}

func (cdc *ConsensusCoreMock) BroadcastMessenger() consensus.BroadcastMessenger {
Expand Down Expand Up @@ -89,8 +89,8 @@ func (cdc *ConsensusCoreMock) SetBlockProcessor(blockProcessor process.BlockProc
cdc.blockProcessor = blockProcessor
}

func (cdc *ConsensusCoreMock) SetBootStrapper(bootstraper process.Bootstrapper) {
cdc.bootstraper = bootstraper
func (cdc *ConsensusCoreMock) SetBootStrapper(bootstrapper process.Bootstrapper) {
cdc.bootstrapper = bootstrapper
}

func (cdc *ConsensusCoreMock) SetBroadcastMessenger(broadcastMessenger consensus.BroadcastMessenger) {
Expand Down
4 changes: 2 additions & 2 deletions consensus/mock/mockTestInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func InitConsensusCore() *ConsensusCoreMock {
SetBlockBroadcastRoundCalled: func(nonce uint64, round int32) {
},
}
bootstraperMock := &BootstraperMock{}
bootstrapperMock := &BootstrapperMock{}
broadcastMessengerMock := &BroadcastMessengerMock{
BroadcastConsensusMessageCalled: func(message *consensus.Message) error {
return nil
Expand All @@ -128,7 +128,7 @@ func InitConsensusCore() *ConsensusCoreMock {
blockChain,
blockProcessorMock,
blockTrackerMock,
bootstraperMock,
bootstrapperMock,
broadcastMessengerMock,
chronologyHandlerMock,
hasherMock,
Expand Down
4 changes: 2 additions & 2 deletions consensus/spos/bls/blsSubroundsFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestFactory_NewFactoryNilBlockProcessorShouldFail(t *testing.T) {
assert.Equal(t, spos.ErrNilBlockProcessor, err)
}

func TestFactory_NewFactoryNilBootstraperShouldFail(t *testing.T) {
func TestFactory_NewFactoryNilBootstrapperShouldFail(t *testing.T) {
t.Parallel()

consensusState := initConsensusState()
Expand All @@ -152,7 +152,7 @@ func TestFactory_NewFactoryNilBootstraperShouldFail(t *testing.T) {
)

assert.Nil(t, fct)
assert.Equal(t, spos.ErrNilBlootstraper, err)
assert.Equal(t, spos.ErrNilBootstrapper, err)
}

func TestFactory_NewFactoryNilChronologyHandlerShouldFail(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/spos/bls/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (fct *factory) BlockProcessor() process.BlockProcessor {
return fct.consensusCore.BlockProcessor()
}

func (fct *factory) Bootstraper() process.Bootstrapper {
func (fct *factory) Bootstrapper() process.Bootstrapper {
return fct.consensusCore.BootStrapper()
}

Expand Down
4 changes: 2 additions & 2 deletions consensus/spos/bn/bnSubroundsFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestFactory_NewFactoryNilBlockProcessorShouldFail(t *testing.T) {
assert.Equal(t, spos.ErrNilBlockProcessor, err)
}

func TestFactory_NewFactoryNilBootstraperShouldFail(t *testing.T) {
func TestFactory_NewFactoryNilBootstrapperShouldFail(t *testing.T) {
t.Parallel()

consensusState := initConsensusState()
Expand All @@ -178,7 +178,7 @@ func TestFactory_NewFactoryNilBootstraperShouldFail(t *testing.T) {
)

assert.Nil(t, fct)
assert.Equal(t, spos.ErrNilBlootstraper, err)
assert.Equal(t, spos.ErrNilBootstrapper, err)
}

func TestFactory_NewFactoryNilChronologyHandlerShouldFail(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/spos/bn/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (fct *factory) BlockProcessor() process.BlockProcessor {
return fct.consensusCore.BlockProcessor()
}

func (fct *factory) Bootstraper() process.Bootstrapper {
func (fct *factory) Bootstrapper() process.Bootstrapper {
return fct.consensusCore.BootStrapper()
}

Expand Down
24 changes: 12 additions & 12 deletions consensus/spos/commonSubround/subroundStartRound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestSubroundStartRound_NewSubroundStartRoundNilBlockChainShouldFail(t *test
assert.Equal(t, spos.ErrNilBlockChain, err)
}

func TestSubroundStartRound_NewSubroundStartRoundNilBootstraperShouldFail(t *testing.T) {
func TestSubroundStartRound_NewSubroundStartRoundNilBootstrapperShouldFail(t *testing.T) {
t.Parallel()

container := mock.InitConsensusCore()
Expand All @@ -107,7 +107,7 @@ func TestSubroundStartRound_NewSubroundStartRoundNilBootstraperShouldFail(t *tes
srStartRound, err := defaultSubroundStartRoundFromSubround(sr)

assert.Nil(t, srStartRound)
assert.Equal(t, spos.ErrNilBlootstraper, err)
assert.Equal(t, spos.ErrNilBootstrapper, err)
}

func TestSubroundStartRound_NewSubroundStartRoundNilConsensusStateShouldFail(t *testing.T) {
Expand Down Expand Up @@ -269,12 +269,12 @@ func TestSubroundStartRound_DoStartRoundConsensusCheckShouldReturnTrueWhenRoundI
func TestSubroundStartRound_DoStartRoundConsensusCheckShouldReturnTrueWhenInitCurrentRoundReturnTrue(t *testing.T) {
t.Parallel()

boostraperMock := &mock.BootstraperMock{ShouldSyncCalled: func() bool {
bootstrapperMock := &mock.BootstrapperMock{ShouldSyncCalled: func() bool {
return false
}}

container := mock.InitConsensusCore()
container.SetBootStrapper(boostraperMock)
container.SetBootStrapper(bootstrapperMock)

sr := *initSubroundStartRoundWithContainer(container)

Expand All @@ -285,12 +285,12 @@ func TestSubroundStartRound_DoStartRoundConsensusCheckShouldReturnTrueWhenInitCu
func TestSubroundStartRound_DoStartRoundConsensusCheckShouldReturnFalseWhenInitCurrentRoundReturnFalse(t *testing.T) {
t.Parallel()

bootstraperMock := &mock.BootstraperMock{ShouldSyncCalled: func() bool {
bootstrapperMock := &mock.BootstrapperMock{ShouldSyncCalled: func() bool {
return true
}}

container := mock.InitConsensusCore()
container.SetBootStrapper(bootstraperMock)
container.SetBootStrapper(bootstrapperMock)
container.SetRounder(initRounderMock())

sr := *initSubroundStartRoundWithContainer(container)
Expand All @@ -302,13 +302,13 @@ func TestSubroundStartRound_DoStartRoundConsensusCheckShouldReturnFalseWhenInitC
func TestSubroundStartRound_InitCurrentRoundShouldReturnFalseWhenShouldSyncReturnTrue(t *testing.T) {
t.Parallel()

bootstraperMock := &mock.BootstraperMock{}
bootstrapperMock := &mock.BootstrapperMock{}

bootstraperMock.ShouldSyncCalled = func() bool {
bootstrapperMock.ShouldSyncCalled = func() bool {
return true
}
container := mock.InitConsensusCore()
container.SetBootStrapper(bootstraperMock)
container.SetBootStrapper(bootstrapperMock)

srStartRound := *initSubroundStartRoundWithContainer(container)

Expand Down Expand Up @@ -405,14 +405,14 @@ func TestSubroundStartRound_InitCurrentRoundShouldReturnFalseWhenTimeIsOut(t *te
func TestSubroundStartRound_InitCurrentRoundShouldReturnTrue(t *testing.T) {
t.Parallel()

bootstraperMock := &mock.BootstraperMock{}
bootstrapperMock := &mock.BootstrapperMock{}

bootstraperMock.ShouldSyncCalled = func() bool {
bootstrapperMock.ShouldSyncCalled = func() bool {
return false
}

container := mock.InitConsensusCore()
container.SetBootStrapper(bootstraperMock)
container.SetBootStrapper(bootstrapperMock)

srStartRound := *initSubroundStartRoundWithContainer(container)

Expand Down
8 changes: 4 additions & 4 deletions consensus/spos/consensusCore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ConsensusCore struct {
blockChain data.ChainHandler
blockProcessor process.BlockProcessor
blocksTracker process.BlocksTracker
bootstraper process.Bootstrapper
bootstrapper process.Bootstrapper
broadcastMessenger consensus.BroadcastMessenger
chronologyHandler consensus.ChronologyHandler
hasher hashing.Hasher
Expand All @@ -36,7 +36,7 @@ func NewConsensusCore(
blockChain data.ChainHandler,
blockProcessor process.BlockProcessor,
blocksTracker process.BlocksTracker,
bootstraper process.Bootstrapper,
bootstrapper process.Bootstrapper,
broadcastMessenger consensus.BroadcastMessenger,
chronologyHandler consensus.ChronologyHandler,
hasher hashing.Hasher,
Expand All @@ -53,7 +53,7 @@ func NewConsensusCore(
blockChain,
blockProcessor,
blocksTracker,
bootstraper,
bootstrapper,
broadcastMessenger,
chronologyHandler,
hasher,
Expand Down Expand Up @@ -92,7 +92,7 @@ func (cc *ConsensusCore) BlocksTracker() process.BlocksTracker {

// BootStrapper gets the Bootstrapper stored in the ConsensusCore
func (cc *ConsensusCore) BootStrapper() process.Bootstrapper {
return cc.bootstraper
return cc.bootstrapper
}

// BroadcastMessenger gets the BroadcastMessenger stored in the ConsensusCore
Expand Down
2 changes: 1 addition & 1 deletion consensus/spos/consensusCoreValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func ValidateConsensusCore(container ConsensusCoreHandler) error {
return ErrNilBlocksTracker
}
if container.BootStrapper() == nil {
return ErrNilBlootstraper
return ErrNilBootstrapper
}
if container.BroadcastMessenger() == nil {
return ErrNilBroadcastMessenger
Expand Down

0 comments on commit bd54836

Please sign in to comment.