From c0b7ddfcbcc7325c08e91b03998b60fd98285878 Mon Sep 17 00:00:00 2001 From: Yang Hau Date: Mon, 25 Sep 2023 19:30:17 +0200 Subject: [PATCH] feat: Make chain setting configurable --- components/chains/component.go | 5 +++++ components/chains/params.go | 4 ++++ packages/chain/node.go | 24 +++++++++++++----------- packages/chain/state_tracker.go | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/components/chains/component.go b/components/chains/component.go index 081437f452..7f1b850fe7 100644 --- a/components/chains/component.go +++ b/components/chains/component.go @@ -59,6 +59,11 @@ func initConfigParams(c *dig.Container) error { Component.LogPanic(err) } + chain.RedeliveryPeriod = ParamsChains.RedeliveryPeriod + chain.PrintStatusPeriod = ParamsChains.PrintStatusPeriod + chain.ConsensusInstsInAdvance = ParamsChains.ConsensusInstsInAdvance + chain.AwaitReceiptCleanupEvery = ParamsChains.AwaitReceiptCleanupEvery + return nil } diff --git a/components/chains/params.go b/components/chains/params.go index d979717d85..fce399ee02 100644 --- a/components/chains/params.go +++ b/components/chains/params.go @@ -15,6 +15,10 @@ type ParametersChains struct { PipeliningLimit int `default:"-1" usage:"-1 -- infinite, 0 -- disabled, X -- build the chain if there is up to X transactions unconfirmed by L1."` ConsensusDelay time.Duration `default:"500ms" usage:"Minimal delay between consensus runs."` RecoveryTimeout time.Duration `default:"20s" usage:"Time after which another consensus attempt is made."` + RedeliveryPeriod time.Duration `default:"2s" usage:"the resend period for msg."` + PrintStatusPeriod time.Duration `default:"3s" usage:"the period to print consensus instance status."` + ConsensusInstsInAdvance int `default:"3" usage:""` + AwaitReceiptCleanupEvery int `default:"100" usage:"for every this number AwaitReceipt will be cleaned up"` } type ParametersWAL struct { diff --git a/packages/chain/node.go b/packages/chain/node.go index 481d2aece0..14b2bd1185 100644 --- a/packages/chain/node.go +++ b/packages/chain/node.go @@ -56,14 +56,16 @@ import ( ) const ( - redeliveryPeriod = 2 * time.Second // TODO: Make it configurable? - printStatusPeriod = 3 * time.Second // TODO: Make it configurable? - consensusInstsInAdvance int = 3 // TODO: Make it configurable? - awaitReceiptCleanupEvery int = 100 // TODO: Make it configurable? - msgTypeChainMgr byte = iota ) +var ( + RedeliveryPeriod = 2 * time.Second + PrintStatusPeriod = 3 * time.Second + ConsensusInstsInAdvance = 3 + AwaitReceiptCleanupEvery = 100 +) + type ChainRequests interface { ReceiveOffLedgerRequest(request isc.OffLedgerRequest, sender *cryptolib.PublicKey) error AwaitRequestProcessed(ctx context.Context, requestID isc.RequestID, confirmed bool) <-chan *blocklog.RequestReceipt @@ -427,7 +429,7 @@ func New( chainMetrics.Pipe, cni.listener, ) - cni.chainMgr = gpa.NewAckHandler(cni.me, chainMgr.AsGPA(), redeliveryPeriod) + cni.chainMgr = gpa.NewAckHandler(cni.me, chainMgr.AsGPA(), RedeliveryPeriod) cni.stateMgr = stateMgr cni.mempool = mempool cni.stateTrackerAct = NewStateTracker(ctx, stateMgr, cni.handleStateTrackerActCB, chainMetrics.StateManager.SetChainActiveStateWant, chainMetrics.StateManager.SetChainActiveStateHave, cni.log.Named("ST.ACT")) @@ -522,7 +524,7 @@ func (cni *chainNodeImpl) run(ctx context.Context, cleanupFunc context.CancelFun consOutputPipeOutCh := cni.consOutputPipe.Out() consRecoverPipeOutCh := cni.consRecoverPipe.Out() serversUpdatedPipeOutCh := cni.serversUpdatedPipe.Out() - redeliveryPeriodTicker := time.NewTicker(redeliveryPeriod) + redeliveryPeriodTicker := time.NewTicker(RedeliveryPeriod) consensusDelayTicker := time.NewTicker(cni.consensusDelay) for { if ctx.Err() != nil { @@ -866,7 +868,7 @@ func (cni *chainNodeImpl) ensureConsensusInst(ctx context.Context, needConsensus }) addLogIndex := logIndex - for i := 0; i < consensusInstsInAdvance; i++ { + for i := 0; i < ConsensusInstsInAdvance; i++ { if !consensusInstances.Has(addLogIndex) { consGrCtx, consGrCancel := context.WithCancel(ctx) logIndexCopy := addLogIndex @@ -874,7 +876,7 @@ func (cni *chainNodeImpl) ensureConsensusInst(ctx context.Context, needConsensus consGrCtx, cni.chainID, cni.chainStore, dkShare, &logIndexCopy, cni.nodeIdentity, cni.procCache, cni.mempool, cni.stateMgr, cni.net, cni.validatorAgentID, - cni.recoveryTimeout, redeliveryPeriod, printStatusPeriod, + cni.recoveryTimeout, RedeliveryPeriod, PrintStatusPeriod, cni.chainMetrics.Consensus, cni.chainMetrics.Pipe, cni.log.Named(fmt.Sprintf("C-%v.LI-%v", committeeAddr.String()[:10], logIndexCopy)), @@ -1080,7 +1082,7 @@ func (cni *chainNodeImpl) LatestAliasOutput(freshness StateFreshness) (*isc.Alia } return nil, fmt.Errorf("have no active state") default: - panic(fmt.Errorf("Unexpected StateFreshness: %v", freshness)) + panic(fmt.Errorf("unexpected StateFreshness: %v", freshness)) } } @@ -1119,7 +1121,7 @@ func (cni *chainNodeImpl) LatestState(freshness StateFreshness) (state.State, er } return nil, fmt.Errorf("chain %v has no active state", cni.chainID) default: - panic(fmt.Errorf("Unexpected StateFreshness: %v", freshness)) + panic(fmt.Errorf("unexpected StateFreshness: %v", freshness)) } } diff --git a/packages/chain/state_tracker.go b/packages/chain/state_tracker.go index e15157761c..1282ef5132 100644 --- a/packages/chain/state_tracker.go +++ b/packages/chain/state_tracker.go @@ -63,7 +63,7 @@ func NewStateTracker( nextAO: nil, nextAOCancel: nil, nextAOWaitCh: nil, - awaitReceipt: NewAwaitReceipt(awaitReceiptCleanupEvery, log), + awaitReceipt: NewAwaitReceipt(AwaitReceiptCleanupEvery, log), metricWantStateIndexCB: metricWantStateIndexCB, metricHaveStateIndexCB: metricHaveStateIndexCB, log: log,