@@ -47,7 +47,6 @@ import (
47
47
"github.com/iotexproject/iotex-core/v2/nodeinfo"
48
48
"github.com/iotexproject/iotex-core/v2/p2p"
49
49
"github.com/iotexproject/iotex-core/v2/pkg/log"
50
- "github.com/iotexproject/iotex-core/v2/pkg/util/blockutil"
51
50
"github.com/iotexproject/iotex-core/v2/server/itx/nodestats"
52
51
"github.com/iotexproject/iotex-core/v2/state/factory"
53
52
"github.com/iotexproject/iotex-core/v2/systemcontractindex/stakingindex"
@@ -703,7 +702,14 @@ func (builder *Builder) registerAccountProtocol() error {
703
702
}
704
703
705
704
func (builder * Builder ) registerExecutionProtocol () error {
706
- return execution .NewProtocol (builder .cs .blockdao .GetBlockHash , rewarding .DepositGas , builder .cs .blockTimeCalculator .CalculateBlockTime ).Register (builder .cs .registry )
705
+ dao := builder .cs .BlockDAO ()
706
+ return execution .NewProtocol (builder .cs .blockdao .GetBlockHash , rewarding .DepositGas , func (u uint64 ) (time.Time , error ) {
707
+ header , err := dao .HeaderByHeight (u )
708
+ if err != nil {
709
+ return time.Time {}, err
710
+ }
711
+ return header .Timestamp (), nil
712
+ }).Register (builder .cs .registry )
707
713
}
708
714
709
715
func (builder * Builder ) registerRollDPoSProtocol () error {
@@ -721,7 +727,13 @@ func (builder *Builder) registerRollDPoSProtocol() error {
721
727
factory := builder .cs .factory
722
728
dao := builder .cs .blockdao
723
729
chain := builder .cs .chain
724
- getBlockTime := builder .cs .blockTimeCalculator .CalculateBlockTime
730
+ getBlockTime := func (height uint64 ) (time.Time , error ) {
731
+ header , err := chain .BlockHeaderByHeight (height )
732
+ if err != nil {
733
+ return time.Time {}, err
734
+ }
735
+ return header .Timestamp (), nil
736
+ }
725
737
pollProtocol , err := poll .NewProtocol (
726
738
builder .cfg .Consensus .Scheme ,
727
739
builder .cfg .Chain ,
@@ -779,19 +791,6 @@ func (builder *Builder) registerRollDPoSProtocol() error {
779
791
return pollProtocol .Register (builder .cs .registry )
780
792
}
781
793
782
- func (builder * Builder ) buildBlockTimeCalculator () (err error ) {
783
- consensusCfg := consensusfsm .NewConsensusConfig (builder .cfg .Consensus .RollDPoS .FSM , builder .cfg .DardanellesUpgrade , builder .cfg .Genesis , builder .cfg .Consensus .RollDPoS .Delay )
784
- dao := builder .cs .BlockDAO ()
785
- builder .cs .blockTimeCalculator , err = blockutil .NewBlockTimeCalculator (consensusCfg .BlockInterval , builder .cs .Blockchain ().TipHeight , func (height uint64 ) (time.Time , error ) {
786
- blk , err := dao .GetBlockByHeight (height )
787
- if err != nil {
788
- return time.Time {}, err
789
- }
790
- return blk .Timestamp (), nil
791
- })
792
- return err
793
- }
794
-
795
794
func (builder * Builder ) buildConsensusComponent () error {
796
795
p2pAgent := builder .cs .p2pAgent
797
796
copts := []consensus.Option {
@@ -852,9 +851,6 @@ func (builder *Builder) build(forSubChain, forTest bool) (*ChainService, error)
852
851
if err := builder .buildBlockchain (forSubChain , forTest ); err != nil {
853
852
return nil , err
854
853
}
855
- if err := builder .buildBlockTimeCalculator (); err != nil {
856
- return nil , err
857
- }
858
854
// staking protocol need to be put in registry before poll protocol when enabling
859
855
if err := builder .registerStakingProtocol (); err != nil {
860
856
return nil , errors .Wrap (err , "failed to register staking protocol" )
0 commit comments