Skip to content

Commit

Permalink
Merge branch 'development' into EN-4524-update-kyber-library
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau authored Oct 20, 2019
2 parents c474c3e + 5467344 commit 7a5be9e
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 38 deletions.
5 changes: 5 additions & 0 deletions consensus/mock/forkDetectorMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ForkDetectorMock struct {
GetHighestFinalBlockNonceCalled func() uint64
ProbableHighestNonceCalled func() uint64
ResetProbableHighestNonceIfNeededCalled func()
ResetProbableHighestNonceCalled func()
}

func (fdm *ForkDetectorMock) AddHeader(header data.HeaderHandler, hash []byte, state process.BlockHeaderState, finalHeaders []data.HeaderHandler, finalHeadersHashes [][]byte) error {
Expand All @@ -38,6 +39,10 @@ func (fdm *ForkDetectorMock) ResetProbableHighestNonceIfNeeded() {
fdm.ResetProbableHighestNonceIfNeededCalled()
}

func (fdm *ForkDetectorMock) ResetProbableHighestNonce() {
fdm.ResetProbableHighestNonceCalled()
}

// IsInterfaceNil returns true if there is no value under the interface
func (fdm *ForkDetectorMock) IsInterfaceNil() bool {
if fdm == nil {
Expand Down
6 changes: 3 additions & 3 deletions consensus/spos/commonSubround/subroundStartRound.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ func (sr *SubroundStartRound) generateNextConsensusGroup(roundIndex int64) error
return err
}

log.Info(fmt.Sprintf("consensus group for round %d is formed by next validators:\n",
log.Debug(fmt.Sprintf("consensus group for round %d is formed by next validators:\n",
roundIndex))

for i := 0; i < len(nextConsensusGroup); i++ {
log.Info(fmt.Sprintf("%s", core.GetTrimmedPk(hex.EncodeToString([]byte(nextConsensusGroup[i])))))
log.Debug(fmt.Sprintf("%s", core.GetTrimmedPk(hex.EncodeToString([]byte(nextConsensusGroup[i])))))
}

log.Info(fmt.Sprintf("\n"))
log.Debug(fmt.Sprintf("\n"))

sr.SetConsensusGroup(nextConsensusGroup)

Expand Down
5 changes: 5 additions & 0 deletions integrationTests/mock/forkDetectorMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ForkDetectorMock struct {
GetHighestFinalBlockNonceCalled func() uint64
ProbableHighestNonceCalled func() uint64
ResetProbableHighestNonceIfNeededCalled func()
ResetProbableHighestNonceCalled func()
}

// AddHeader is a mock implementation for AddHeader
Expand Down Expand Up @@ -44,6 +45,10 @@ func (fdm *ForkDetectorMock) ResetProbableHighestNonceIfNeeded() {
fdm.ResetProbableHighestNonceIfNeededCalled()
}

func (fdm *ForkDetectorMock) ResetProbableHighestNonce() {
fdm.ResetProbableHighestNonceCalled()
}

// IsInterfaceNil returns true if there is no value under the interface
func (fdm *ForkDetectorMock) IsInterfaceNil() bool {
if fdm == nil {
Expand Down
5 changes: 5 additions & 0 deletions node/mock/forkDetectorMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ForkDetectorMock struct {
GetHighestFinalBlockNonceCalled func() uint64
ProbableHighestNonceCalled func() uint64
ResetProbableHighestNonceIfNeededCalled func()
ResetProbableHighestNonceCalled func()
}

// AddHeader is a mock implementation for AddHeader
Expand Down Expand Up @@ -44,6 +45,10 @@ func (fdm *ForkDetectorMock) ResetProbableHighestNonceIfNeeded() {
fdm.ResetProbableHighestNonceIfNeededCalled()
}

func (fdm *ForkDetectorMock) ResetProbableHighestNonce() {
fdm.ResetProbableHighestNonceCalled()
}

// IsInterfaceNil returns true if there is no value under the interface
func (fdm *ForkDetectorMock) IsInterfaceNil() bool {
if fdm == nil {
Expand Down
2 changes: 1 addition & 1 deletion process/block/preprocess/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (txs *transactions) CreateAndProcessMiniBlock(

isGasLimitReached := addedGasLimitPerCrossShardMiniblock+currTxGasLimit > process.MaxGasLimitPerMiniBlock
if isGasLimitReached {
log.Info(fmt.Sprintf("max gas limit per mini block is reached: added %d txs from %d txs\n",
log.Debug(fmt.Sprintf("max gas limit per mini block is reached: added %d txs from %d txs\n",
len(miniBlock.TxHashes),
len(orderedTxs)))
continue
Expand Down
5 changes: 5 additions & 0 deletions process/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,8 @@ func SortHeadersByNonce(headers []data.HeaderHandler) {
})
}
}

// IsInProperRound checks if the given round index satisfies the round modulus trigger
func IsInProperRound(index int64) bool {
return index%RoundModulusTrigger == 0
}
5 changes: 4 additions & 1 deletion process/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const MaxNoncesDifference = 5

// TODO - calculate exactly in case of the VM, for every VM to have a similar constant, operations / seconds
const MaxGasLimitPerMiniBlock = uint64(100000)
const MaxRequestsWithTimeoutAllowed = 10
const MaxRequestsWithTimeoutAllowed = 3

// MaxHeadersToRequestInAdvance defines the maximum number of headers which will be requested in advance if they are missing
const MaxHeadersToRequestInAdvance = 10

// RoundModulusTrigger defines a round modulus on which a trigger for an action will be released
const RoundModulusTrigger = 5
1 change: 1 addition & 0 deletions process/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ type ForkDetector interface {
GetHighestFinalBlockNonce() uint64
ProbableHighestNonce() uint64
ResetProbableHighestNonceIfNeeded()
ResetProbableHighestNonce()
IsInterfaceNil() bool
}

Expand Down
5 changes: 5 additions & 0 deletions process/mock/forkDetectorMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ForkDetectorMock struct {
GetHighestFinalBlockNonceCalled func() uint64
ProbableHighestNonceCalled func() uint64
ResetProbableHighestNonceIfNeededCalled func()
ResetProbableHighestNonceCalled func()
}

func (fdm *ForkDetectorMock) AddHeader(header data.HeaderHandler, hash []byte, state process.BlockHeaderState, finalHeaders []data.HeaderHandler, finalHeadersHashes [][]byte) error {
Expand All @@ -38,6 +39,10 @@ func (fdm *ForkDetectorMock) ResetProbableHighestNonceIfNeeded() {
fdm.ResetProbableHighestNonceIfNeededCalled()
}

func (fdm *ForkDetectorMock) ResetProbableHighestNonce() {
fdm.ResetProbableHighestNonceCalled()
}

// IsInterfaceNil returns true if there is no value under the interface
func (fdm *ForkDetectorMock) IsInterfaceNil() bool {
if fdm == nil {
Expand Down
18 changes: 12 additions & 6 deletions process/sync/baseForkDetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,18 @@ func (bfd *baseForkDetector) ResetProbableHighestNonceIfNeeded() {
// consensus group size, could keep all the shard in sync mode, by creating fake blocks higher than current
// committed block + 1, which could not be verified by hash -> prev hash and only by rand seed -> prev random seed
roundsWithoutReceivedBlock := bfd.rounder.Index() - int64(bfd.lastBlockRound())
if roundsWithoutReceivedBlock > maxRoundsToWait {
probableHighestNonce := bfd.ProbableHighestNonce()
checkpointNonce := bfd.lastCheckpoint().nonce
if probableHighestNonce > checkpointNonce {
bfd.setProbableHighestNonce(checkpointNonce)
}
isInProperRound := process.IsInProperRound(bfd.rounder.Index())
if roundsWithoutReceivedBlock > maxRoundsToWait && isInProperRound {
bfd.ResetProbableHighestNonce()
}
}

// ResetProbableHighestNonce resets the probableHighestNonce to checkpoint
func (bfd *baseForkDetector) ResetProbableHighestNonce() {
probableHighestNonce := bfd.ProbableHighestNonce()
checkpointNonce := bfd.lastCheckpoint().nonce
if probableHighestNonce > checkpointNonce {
bfd.setProbableHighestNonce(checkpointNonce)
}
}

Expand Down
4 changes: 4 additions & 0 deletions process/sync/baseForkDetector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,10 @@ func TestBasicForkDetector_ResetProbableHighestNonce(t *testing.T) {

rounderMock.RoundIndex = 22
bfd.ResetProbableHighestNonceIfNeeded()
assert.Equal(t, uint64(11), bfd.ProbableHighestNonce())

rounderMock.RoundIndex = 25
bfd.ResetProbableHighestNonceIfNeeded()
assert.Equal(t, uint64(10), bfd.ProbableHighestNonce())
}

Expand Down
5 changes: 4 additions & 1 deletion process/sync/baseSync.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const sleepTime = 5 * time.Millisecond

// maxRoundsToWait defines the maximum rounds to wait, when bootstrapping, after which the node will add an empty
// block through recovery mechanism, if its block request is not resolved and no new block header is received meantime
const maxRoundsToWait = 5
const maxRoundsToWait = 3

// maxHeadersToRequestInAdvance defines the maximum number of headers which will be requested in advance if they are missing
const maxHeadersToRequestInAdvance = 10

type notarizedInfo struct {
lastNotarized map[uint32]uint64
Expand Down
6 changes: 5 additions & 1 deletion process/sync/metablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,17 @@ func (boot *MetaBootstrap) doJobOnSyncBlockFail(hdr *block.MetaBlock, err error)
boot.requestsWithTimeout++
}

shouldRollBack := err != process.ErrTimeIsOut || boot.requestsWithTimeout >= process.MaxRequestsWithTimeoutAllowed
allowedRequestsWithTimeOutHaveReached := boot.requestsWithTimeout >= process.MaxRequestsWithTimeoutAllowed
isInProperRound := process.IsInProperRound(boot.rounder.Index())

shouldRollBack := err != process.ErrTimeIsOut || (allowedRequestsWithTimeOutHaveReached && isInProperRound)
if shouldRollBack {
boot.requestsWithTimeout = 0

if hdr != nil {
hash := boot.removeHeaderFromPools(hdr)
boot.forkDetector.RemoveHeaders(hdr.Nonce, hash)
boot.forkDetector.ResetProbableHighestNonce()
}

errNotCritical := boot.forkChoice(false)
Expand Down
1 change: 1 addition & 0 deletions process/sync/metablock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ func TestMetaBootstrap_SyncBlockShouldReturnErrorWhenProcessBlockFailed(t *testi
return 2
}
forkDetector.RemoveHeadersCalled = func(nonce uint64, hash []byte) {}
forkDetector.ResetProbableHighestNonceCalled = func() {}

shardCoordinator := mock.NewOneShardCoordinatorMock()
account := &mock.AccountsStub{}
Expand Down
6 changes: 5 additions & 1 deletion process/sync/shardblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,17 @@ func (boot *ShardBootstrap) doJobOnSyncBlockFail(hdr *block.Header, err error) {
boot.requestsWithTimeout++
}

shouldRollBack := err != process.ErrTimeIsOut || boot.requestsWithTimeout >= process.MaxRequestsWithTimeoutAllowed
allowedRequestsWithTimeOutHaveReached := boot.requestsWithTimeout >= process.MaxRequestsWithTimeoutAllowed
isInProperRound := process.IsInProperRound(boot.rounder.Index())

shouldRollBack := err != process.ErrTimeIsOut || (allowedRequestsWithTimeOutHaveReached && isInProperRound)
if shouldRollBack {
boot.requestsWithTimeout = 0

if hdr != nil {
hash := boot.removeHeaderFromPools(hdr)
boot.forkDetector.RemoveHeaders(hdr.Nonce, hash)
boot.forkDetector.ResetProbableHighestNonce()
}

errNotCritical := boot.forkChoice(false)
Expand Down
1 change: 1 addition & 0 deletions process/sync/shardblock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@ func TestBootstrap_SyncBlockShouldReturnErrorWhenProcessBlockFailed(t *testing.T
return 2
}
forkDetector.RemoveHeadersCalled = func(nonce uint64, hash []byte) {}
forkDetector.ResetProbableHighestNonceCalled = func() {}

shardCoordinator := mock.NewOneShardCoordinatorMock()
account := &mock.AccountsStub{}
Expand Down
4 changes: 1 addition & 3 deletions sharding/multiShardCoordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (msc *multiShardCoordinator) calculateMasks() (uint32, uint32) {
return (1 << uint(n)) - 1, (1 << uint(n-1)) - 1
}

//TODO: This method should be changed, as value 0xFF in the last byte of the given address could exist also in shards
func isMetaChainShardId(identifier []byte) bool {
for i := 0; i < len(identifier); i++ {
if identifier[i] != metaChainIdentifier {
Expand All @@ -65,9 +66,6 @@ func (msc *multiShardCoordinator) ComputeId(address state.AddressContainer) uint
}

buffNeeded := address.Bytes()[startingIndex:]
if isMetaChainShardId(buffNeeded) {
return MetachainShardId
}

addr := uint32(0)
for i := 0; i < len(buffNeeded); i++ {
Expand Down
24 changes: 3 additions & 21 deletions statusHandler/view/termuic/termuiRenders/widgetsRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,9 @@ func (wr *WidgetsRender) prepareInstanceInfo() {
countAcceptedBlocks := wr.presenter.GetCountAcceptedBlocks()
rows[5] = []string{fmt.Sprintf("Consensus leader accepted / proposed blocks : %d / %d", countAcceptedBlocks, countLeader)}

switch instanceType {
case string(core.NodeTypeValidator):
rewardsPerHour := wr.presenter.CalculateRewardsPerHour()
rows[6] = []string{fmt.Sprintf("Rewards estimation: %s ERD/h (without fees)", rewardsPerHour)}

var rewardsInfo []string
totalRewardsValue, diffRewards := wr.presenter.GetTotalRewardsValue()
if diffRewards != "0" {
wr.instanceInfo.RowStyles[7] = ui.NewStyle(ui.ColorGreen)
rewardsInfo = []string{fmt.Sprintf("Total rewards %s ERD + %s", totalRewardsValue, diffRewards)}
} else {
wr.instanceInfo.RowStyles[7] = ui.NewStyle(ui.ColorWhite)
rewardsInfo = []string{fmt.Sprintf("Total rewards %s ERD", totalRewardsValue)}
}
rows[7] = rewardsInfo

default:
rows[6] = []string{""}
rows[7] = []string{""}

}
//TODO: The rewards calculation for printing should be fixed
rows[6] = []string{""}
rows[7] = []string{""}

wr.instanceInfo.Title = "Elrond instance info"
wr.instanceInfo.RowSeparator = false
Expand Down

0 comments on commit 7a5be9e

Please sign in to comment.