Skip to content

Commit

Permalink
feat(zetaclient): process first solana transaction faster
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Feb 1, 2025
1 parent 1375375 commit e28320a
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions zetaclient/chains/solana/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ func (s *Solana) scheduleCCTX(ctx context.Context) error {
zetaHeight = uint64(zetaBlock.Block.Height)

// #nosec G115 positive
interval = uint64(s.observer.ChainParams().OutboundScheduleInterval)
scheduleLookahead = s.observer.ChainParams().OutboundScheduleLookahead
scheduleLookback = uint64(float64(scheduleLookahead) * outboundLookbackFactor)
interval = uint64(s.observer.ChainParams().OutboundScheduleInterval)
scheduleLookahead = s.observer.ChainParams().OutboundScheduleLookahead
scheduleLookback = uint64(float64(scheduleLookahead) * outboundLookbackFactor)
needsProcessingCtr = 0
)

cctxList, _, err := s.observer.ZetacoreClient().ListPendingCCTX(ctx, chainID)
Expand All @@ -154,18 +155,16 @@ func (s *Solana) scheduleCCTX(ctx context.Context) error {
// schedule keysign for each pending cctx
for _, cctx := range cctxList {
var (
params = cctx.GetCurrentOutboundParam()
nonce = params.TssNonce
outboundID = base.OutboundIDFromCCTX(cctx)
params = cctx.GetCurrentOutboundParam()
inboundParams = cctx.GetInboundParams()
nonce = params.TssNonce
outboundID = base.OutboundIDFromCCTX(cctx)

Check warning on line 161 in zetaclient/chains/solana/solana.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/solana.go#L158-L161

Added lines #L158 - L161 were not covered by tests
)

switch {
case params.ReceiverChainId != chainID:
s.outboundLogger(outboundID).Error().Msg("chain id mismatch")
continue
case s.signer.IsOutboundActive(outboundID):
// noop
continue
case params.TssNonce > cctxList[0].GetCurrentOutboundParam().TssNonce+scheduleLookback:
return fmt.Errorf(
"nonce %d is too high (%s). Earliest nonce %d",
Expand All @@ -175,6 +174,20 @@ func (s *Solana) scheduleCCTX(ctx context.Context) error {
)
}

// schedule newly created cctx right away, no need to wait for next interval
// 1. schedule the very first cctx (there can be multiple) created in the last Zeta block.
// 2. schedule new cctx only when there is no other older cctx to process
isCCTXNewlyCreated := inboundParams.ObservedExternalHeight == zetaHeight
shouldProcessCCTXImmedately := isCCTXNewlyCreated && needsProcessingCtr == 0

// even if the outbound is currently active, we should increment this counter
// to avoid immediate processing logic
needsProcessingCtr++

if s.signer.IsOutboundActive(outboundID) {
continue

Check warning on line 188 in zetaclient/chains/solana/solana.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/solana.go#L180-L188

Added lines #L180 - L188 were not covered by tests
}

// vote outbound if it's already confirmed
continueKeysign, err := s.observer.VoteOutboundIfConfirmed(ctx, cctx)
switch {
Expand All @@ -186,8 +199,10 @@ func (s *Solana) scheduleCCTX(ctx context.Context) error {
continue
}

shouldScheduleProcess := nonce%interval == zetaHeight%interval

Check warning on line 203 in zetaclient/chains/solana/solana.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/solana.go#L202-L203

Added lines #L202 - L203 were not covered by tests
// schedule a TSS keysign
if nonce%interval == zetaHeight%interval {
if shouldProcessCCTXImmedately || shouldScheduleProcess {

Check warning on line 205 in zetaclient/chains/solana/solana.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/solana.go#L205

Added line #L205 was not covered by tests
go s.signer.TryProcessOutbound(
ctx,
cctx,
Expand Down

0 comments on commit e28320a

Please sign in to comment.