Skip to content

Commit f39c57c

Browse files
authored
add system level config for change some const parameters (#1268)
1 parent 8017dc1 commit f39c57c

51 files changed

Lines changed: 507 additions & 395 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/admin/health/health.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ type Health struct {
1919
p2p *comm.Communicator
2020
}
2121

22-
const (
23-
defaultBlockTolerance = time.Duration(2*thor.BlockInterval) * time.Second // 2 blocks tolerance
24-
defaultMinPeerCount = 2
25-
)
22+
const defaultMinPeerCount = 2
23+
24+
var defaultBlockTolerance = time.Duration(2*thor.BlockInterval()) * time.Second // 2 blocks tolerance
2625

2726
func New(repo *chain.Repository, p2p *comm.Communicator) *Health {
2827
return &Health{

api/restutil/revisions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func GetSummaryAndState(
126126
// call to header.Signer(), the error should be ignored.
127127
builder := new(block.Builder).
128128
ParentID(best.Header.ID()).
129-
Timestamp(best.Header.Timestamp() + thor.BlockInterval).
129+
Timestamp(best.Header.Timestamp() + thor.BlockInterval()).
130130
TotalScore(best.Header.TotalScore()).
131131
GasLimit(best.Header.GasLimit()).
132132
Beneficiary(best.Header.Beneficiary()).

api/restutil/revisions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func TestGetSummaryAndState(t *testing.T) {
179179
summary, _, err = GetSummaryAndState(&Revision{revNext}, thorChain.Repo(), thorChain.Engine(), thorChain.Stater(), thorChain.GetForkConfig())
180180
assert.Nil(t, err)
181181
assert.Equal(t, summary.Header.Number(), b.Header().Number()+1)
182-
assert.Equal(t, summary.Header.Timestamp(), b.Header().Timestamp()+thor.BlockInterval)
182+
assert.Equal(t, summary.Header.Timestamp(), b.Header().Timestamp()+thor.BlockInterval())
183183
assert.Equal(t, summary.Header.GasUsed(), uint64(0))
184184
assert.Equal(t, summary.Header.ReceiptsRoot(), tx.Receipts{}.RootHash())
185185
assert.Equal(t, len(summary.Txs), 0)

api/subscriptions/pending_tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (p *pendingTx) DispatchLoop(done <-chan struct{}) {
6060
}
6161
now := time.Now().Unix()
6262
// ignored if seen within half block interval
63-
if seen, ok := knownTx.Get(txEv.Tx.ID()); ok && now-seen.(int64) <= int64(thor.BlockInterval/2) {
63+
if seen, ok := knownTx.Get(txEv.Tx.ID()); ok && now-seen.(int64) <= int64(thor.BlockInterval()/2) {
6464
continue
6565
}
6666
knownTx.Add(txEv.Tx.ID(), now)

bft/engine.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ func (engine *Engine) Justified() (thor.Bytes32, error) {
9393
finalized := engine.Finalized()
9494

9595
// if head is in the first epoch and not concluded yet
96-
if head.Number() < getCheckPoint(engine.forkConfig.FINALITY)+thor.CheckpointInterval-1 {
96+
if head.Number() < getCheckPoint(engine.forkConfig.FINALITY)+thor.EpochLength()-1 {
9797
return finalized, nil
9898
}
9999

100100
// find the recent concluded checkpoint
101101
concluded := getCheckPoint(head.Number())
102102
if head.Number() < getStorePoint(head.Number()) {
103-
concluded -= thor.CheckpointInterval
103+
concluded -= thor.EpochLength()
104104
}
105105

106106
headChain := engine.repo.NewChain(head.ID())
@@ -222,7 +222,7 @@ func (engine *Engine) ShouldVote(parentID thor.Bytes32) (bool, error) {
222222
}
223223

224224
// do not vote COM at the first round
225-
if absRound := (block.Number(parentID)+1)/thor.CheckpointInterval - engine.forkConfig.FINALITY/thor.CheckpointInterval; absRound == 0 {
225+
if absRound := (block.Number(parentID)+1)/thor.EpochLength() - engine.forkConfig.FINALITY/thor.EpochLength(); absRound == 0 {
226226
return false, nil
227227
}
228228

@@ -252,7 +252,7 @@ func (engine *Engine) ShouldVote(parentID thor.Bytes32) (bool, error) {
252252
recentJC = checkpoint
253253
} else {
254254
// if current round is not justified, find the most recent justified checkpoint
255-
prev, err := chain.GetBlockID(getStorePoint(block.Number(parentID) - thor.CheckpointInterval))
255+
prev, err := chain.GetBlockID(getStorePoint(block.Number(parentID) - thor.EpochLength()))
256256
if err != nil {
257257
return false, err
258258
}
@@ -381,15 +381,15 @@ func (engine *Engine) findCheckpointByQuality(target uint32, finalized, headID t
381381

382382
c := engine.repo.NewChain(headID)
383383
get := func(i int) (uint32, error) {
384-
id, err := c.GetBlockID(getStorePoint(searchStart + uint32(i)*thor.CheckpointInterval))
384+
id, err := c.GetBlockID(getStorePoint(searchStart + uint32(i)*thor.EpochLength()))
385385
if err != nil {
386386
return 0, err
387387
}
388388
return engine.getQuality(id)
389389
}
390390

391391
// sort.Search searches from [0, n)
392-
n := int((block.Number(headID)-searchStart)/thor.CheckpointInterval) + 1
392+
n := int((block.Number(headID)-searchStart)/thor.EpochLength()) + 1
393393
num := sort.Search(n, func(i int) bool {
394394
quality, err := get(i)
395395
if err != nil {
@@ -413,7 +413,7 @@ func (engine *Engine) findCheckpointByQuality(target uint32, finalized, headID t
413413
return thor.Bytes32{}, errors.New("failed to find the block by quality")
414414
}
415415

416-
return c.GetBlockID(searchStart + uint32(num)*thor.CheckpointInterval)
416+
return c.GetBlockID(searchStart + uint32(num)*thor.EpochLength())
417417
}
418418

419419
func (engine *Engine) getTotalWeight(sum *chain.BlockSummary) (*big.Int, error) {
@@ -466,7 +466,7 @@ func (engine *Engine) getQuality(id thor.Bytes32) (quality uint32, err error) {
466466
}
467467

468468
func getCheckPoint(blockNum uint32) uint32 {
469-
return blockNum / thor.CheckpointInterval * thor.CheckpointInterval
469+
return blockNum / thor.EpochLength() * thor.EpochLength()
470470
}
471471

472472
func isCheckPoint(blockNum uint32) bool {
@@ -475,7 +475,7 @@ func isCheckPoint(blockNum uint32) bool {
475475

476476
// save quality at the end of round
477477
func getStorePoint(blockNum uint32) uint32 {
478-
return getCheckPoint(blockNum) + thor.CheckpointInterval - 1
478+
return getCheckPoint(blockNum) + thor.EpochLength() - 1
479479
}
480480

481481
type mockedEngine thor.Bytes32

0 commit comments

Comments
 (0)