Skip to content

Commit

Permalink
fix: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Dec 7, 2024
1 parent 13f621e commit 8c5de48
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
7 changes: 6 additions & 1 deletion node/pkg/chain/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ func (t *ChainHelper) SubmitDelegatedFallbackDirect(ctx context.Context, contrac

tx, err = t.GetSignedFromDelegator(tx)
if err != nil {
return t.SubmitDirect(ctx, contractAddress, functionString, args...)
tx, err = utils.MakeDirectTx(ctx, t.client, contractAddress, t.wallet, functionString, t.chainID, nonce, args...)
if err != nil {
return err
}

return utils.SubmitRawTx(ctx, t.client, tx)
}

return utils.SubmitRawTx(ctx, t.client, tx)
Expand Down
15 changes: 0 additions & 15 deletions node/pkg/chain/noncemanagerv2/noncemanagerv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,55 +34,40 @@ func (m *NonceManagerV2) GetNonce(ctx context.Context, address string) (uint64,
defer m.mu.Unlock()

if _, ok := m.noncePool[address]; !ok {
log.Debug().Msgf("Initializing nonce pool for address %s", address)
m.noncePool[address] = make(chan uint64, 30)
if err := m.unsafeRefill(ctx, address); err != nil {
return 0, err
}
log.Debug().Msgf("Nonce pool initialized for address %s", address)
}

log.Debug().Msgf("Checking nonce pool for address %s", address)
if len(m.noncePool[address]) < minimumNoncePoolSize {
log.Debug().Msgf("Low nonce pool size for address %s, refilling...", address)
if err := m.unsafeRefill(ctx, address); err != nil {
return 0, fmt.Errorf("failed to refill nonce pool: %w", err)
}
log.Debug().Msgf("Nonce pool refilled for address %s", address)
}

log.Debug().Msgf("Getting nonce from pool for address %s", address)

nonce := <-m.noncePool[address]
return nonce, nil
}

func (m *NonceManagerV2) unsafeRefill(ctx context.Context, address string) error {
log.Debug().Msgf("refilling nonce pool for address %s", address)
currentNonce, err := utils.GetNonceFromPk(ctx, address, m.client)
if err != nil {
return err
}

log.Debug().Msgf("current nonce for address %s: %d", address, currentNonce)

m.unsafeFlushPool(address)
for i := uint64(0); i < poolSize; i++ {
m.noncePool[address] <- currentNonce + i
log.Debug().Msgf("added nonce %d to pool for address %s", currentNonce+i, address)
}
return nil
}

func (m *NonceManagerV2) unsafeFlushPool(address string) {
log.Debug().Msgf("flushing nonce pool for address %s", address)
if pool, exists := m.noncePool[address]; exists {
for len(pool) > 0 {
<-pool
}
}

log.Debug().Msgf("nonce pool flushed for address %s", address)
}

func (m *NonceManagerV2) refillAll(ctx context.Context) error {
Expand Down
1 change: 0 additions & 1 deletion node/pkg/chain/tests/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ func TestGenerateViewABI(t *testing.T) {
}

func TestSubmitDelegeted(t *testing.T) {
t.Skip()
ctx := context.Background()

kaiaHelper, err := helper.NewChainHelper(ctx)
Expand Down
4 changes: 2 additions & 2 deletions node/script/test_dal_consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {
proofs = append(proofs, klaytncommon.Hex2Bytes(strings.TrimPrefix(entry.Proof, "0x")))

if len(feedHashes) >= 50 {
err = kaiaHelper.SubmitDelegatedFallbackDirect(ctx, contractAddr, SUBMIT_STRICT, maxTxSubmissionRetries, feedHashes, values, timestamps, proofs)
err = kaiaHelper.SubmitDelegatedFallbackDirect(ctx, contractAddr, SUBMIT_STRICT, feedHashes, values, timestamps, proofs)
if err != nil {
log.Error().Err(err).Msg("MakeDirect")
panic(err)
Expand All @@ -87,7 +87,7 @@ func main() {
}
}

err = kaiaHelper.SubmitDelegatedFallbackDirect(ctx, contractAddr, SUBMIT_STRICT, maxTxSubmissionRetries, feedHashes, values, timestamps, proofs)
err = kaiaHelper.SubmitDelegatedFallbackDirect(ctx, contractAddr, SUBMIT_STRICT, feedHashes, values, timestamps, proofs)
if err != nil {
log.Error().Err(err).Msg("MakeDirect")
panic(err)
Expand Down

0 comments on commit 8c5de48

Please sign in to comment.