diff --git a/process/sync/baseForkDetector.go b/process/sync/baseForkDetector.go index c0948f930bb..fe7051fba1b 100644 --- a/process/sync/baseForkDetector.go +++ b/process/sync/baseForkDetector.go @@ -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 } diff --git a/process/sync/baseForkDetector_test.go b/process/sync/baseForkDetector_test.go index 08d0531d1c0..d6d8971159b 100644 --- a/process/sync/baseForkDetector_test.go +++ b/process/sync/baseForkDetector_test.go @@ -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) +} diff --git a/process/sync/export_test.go b/process/sync/export_test.go index dce3655b087..112c57f572f 100644 --- a/process/sync/export_test.go +++ b/process/sync/export_test.go @@ -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) } @@ -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,