Skip to content

Commit

Permalink
Merge pull request #759 from ElrondNetwork/EN-5293-Hot-fix-resolve-pr…
Browse files Browse the repository at this point in the history
…oblem-with-method-computeGenesisTimeFromHeader

EN-5293 : fix problem with method computeGenesisTimeFromHeader from b…
  • Loading branch information
SebastianMarian authored Dec 6, 2019
2 parents 745e8ac + f6fc93f commit 63290a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion process/sync/baseForkDetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,6 @@ func (bfd *baseForkDetector) cleanupReceivedHeadersHigherThanNonce(nonce uint64)
}

func (bfd *baseForkDetector) computeGenesisTimeFromHeader(headerHandler data.HeaderHandler) int64 {
genesisTime := int64(headerHandler.GetTimeStamp() - headerHandler.GetRound()*uint64(bfd.rounder.TimeDuration()))
genesisTime := int64(headerHandler.GetTimeStamp() - headerHandler.GetRound()*uint64(bfd.rounder.TimeDuration().Seconds()))
return genesisTime
}
20 changes: 20 additions & 0 deletions process/sync/baseForkDetector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,3 +916,23 @@ func TestBaseForkDetector_ResetFork(t *testing.T) {
bfd.ResetFork()
assert.False(t, bfd.ShouldForceFork())
}

func TestBaseForkDetector_ComputeTimeDuration(t *testing.T) {
t.Parallel()

roundDuration := uint64(1)
rounderMock := &mock.RounderMock{
RoundTimeDuration: time.Second,
}

genesisTime := int64(9000)
hdrTimeStamp := uint64(10000)
hdrRound := uint64(20)
bfd, _ := sync.NewShardForkDetector(rounderMock, &mock.BlackListHandlerStub{}, genesisTime)

hdr1 := &block.Header{Nonce: 1, Round: hdrRound, PubKeysBitmap: []byte("X"), TimeStamp: hdrTimeStamp}

expectedTimeStamp := hdrTimeStamp - (hdrRound * roundDuration)
timeDuration := bfd.ComputeGenesisTimeFromHeader(hdr1)
assert.Equal(t, int64(expectedTimeStamp), timeDuration)
}
32 changes: 4 additions & 28 deletions process/sync/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,6 @@ func (boot *ShardBootstrap) RequestMiniBlocksFromHeaderWithNonceIfMissing(shardI
boot.requestMiniBlocksFromHeaderWithNonceIfMissing(shardId, nonce)
}

type StorageBootstrapperMock struct {
GetHeaderCalled func(hash []byte) (data.HeaderHandler, error)
GetBlockBodyCalled func(header data.HeaderHandler) (data.BodyHandler, error)
ApplyNotarizedBlocksCalled func(lastNotarized map[uint32]*HdrInfo) error
AddHeaderToForkDetectorCalled func(shardId uint32, nonce uint64, lastNotarizedMeta uint64)
}

func (sbm *StorageBootstrapperMock) getHeader(hash []byte) (data.HeaderHandler, error) {
return sbm.GetHeaderCalled(hash)
}

func (sbm *StorageBootstrapperMock) getBlockBody(header data.HeaderHandler) (data.BodyHandler, error) {
return sbm.GetBlockBodyCalled(header)
}

func (sbm *StorageBootstrapperMock) applyNotarizedBlocks(lastNotarized map[uint32]*HdrInfo) error {

return sbm.ApplyNotarizedBlocksCalled(lastNotarized)
}

// IsInterfaceNil returns true if there is no value under the interface
func (sbm *StorageBootstrapperMock) IsInterfaceNil() bool {
if sbm == nil {
return true
}
return false
}

func (bfd *baseForkDetector) IsHeaderReceivedTooLate(header data.HeaderHandler, state process.BlockHeaderState, finality int64) bool {
return bfd.isHeaderReceivedTooLate(header, state, finality)
}
Expand All @@ -209,6 +181,10 @@ func (bfd *baseForkDetector) AddCheckPoint(round uint64, nonce uint64) {
bfd.addCheckpoint(&checkpointInfo{round: round, nonce: nonce})
}

func (bfd *baseForkDetector) ComputeGenesisTimeFromHeader(headerHandler data.HeaderHandler) int64 {
return bfd.computeGenesisTimeFromHeader(headerHandler)
}

func GetCacherWithHeaders(
hdr1 data.HeaderHandler,
hdr2 data.HeaderHandler,
Expand Down

0 comments on commit 63290a5

Please sign in to comment.