Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make chain setting configurable #2890

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/chains/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions components/chains/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:""`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need descripion

AwaitReceiptCleanupEvery int `default:"100" usage:"for every this number AwaitReceipt will be cleaned up"`
}

type ParametersWAL struct {
Expand Down
24 changes: 13 additions & 11 deletions packages/chain/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -866,15 +868,15 @@ 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
cgr := consGR.New(
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)),
Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/chain/state_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading