Skip to content

Commit

Permalink
make maxRetries func param & try direct submission if delegator sign …
Browse files Browse the repository at this point in the history
…fails
  • Loading branch information
Intizar-T committed Aug 26, 2024
1 parent a8f0693 commit 9d447e2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
5 changes: 2 additions & 3 deletions node/pkg/chain/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,10 @@ func (t *ChainHelper) PublicAddressString() (string, error) {
return address.Hex(), nil
}

func (t *ChainHelper) SubmitDelegatedFallbackDirect(ctx context.Context, contractAddress string, functionString string, args ...interface{}) error {
func (t *ChainHelper) SubmitDelegatedFallbackDirect(ctx context.Context, contractAddress string, functionString string, maxRetrial int, args ...interface{}) error {
var err error
var tx *types.Transaction

maxRetrial := 3
clientIndex := 0

nonce, err := noncemanager.GetAndIncrementNonce(t.wallet)
Expand All @@ -266,7 +265,7 @@ func (t *ChainHelper) SubmitDelegatedFallbackDirect(ctx context.Context, contrac

tx, err = t.GetSignedFromDelegator(tx)
if err != nil {
continue
break // if delegator signing fails, try direct transaction
}

err = utils.SubmitRawTx(ctx, t.clients[clientIndex], tx)
Expand Down
4 changes: 3 additions & 1 deletion node/pkg/chain/helper/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/rs/zerolog/log"
)

const maxTxSubmissionRetries = 3

type SignerConfig struct {
pk string
renewInterval time.Duration
Expand Down Expand Up @@ -235,6 +237,6 @@ func (s *Signer) Renew(ctx context.Context, newPK *ecdsa.PrivateKey, newPkHex st
}

func (s *Signer) signerUpdate(ctx context.Context, newAddr common.Address) error {
return s.chainHelper.SubmitDelegatedFallbackDirect(ctx, s.submissionProxyContractAddr, UpdateSignerFuncSignature, newAddr)
return s.chainHelper.SubmitDelegatedFallbackDirect(ctx, s.submissionProxyContractAddr, UpdateSignerFuncSignature, maxTxSubmissionRetries, newAddr)

}
9 changes: 5 additions & 4 deletions node/pkg/chain/tests/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

var (
InsertProviderUrlQuery = "INSERT INTO provider_urls (chain_id, url, priority) VALUES (@chain_id, @url, @priority)"
maxTxSubmissionRetries = 3
)

func TestNewKaiaHelper(t *testing.T) {
Expand Down Expand Up @@ -267,7 +268,7 @@ func TestSubmitDelegetedFallbackDirect(t *testing.T) {
}
defer kaiaHelper.Close()

err = kaiaHelper.SubmitDelegatedFallbackDirect(ctx, "0x93120927379723583c7a0dd2236fcb255e96949f", "increment()")
err = kaiaHelper.SubmitDelegatedFallbackDirect(ctx, "0x93120927379723583c7a0dd2236fcb255e96949f", "increment()", maxTxSubmissionRetries)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand All @@ -291,7 +292,7 @@ func TestSubmitDelegetedFallbackDirectConcurrent(t *testing.T) {

submitTx := func() {
defer wg.Done()
err := kaiaHelper.SubmitDelegatedFallbackDirect(ctx, "0x93120927379723583c7a0dd2236fcb255e96949f", "increment()")
err := kaiaHelper.SubmitDelegatedFallbackDirect(ctx, "0x93120927379723583c7a0dd2236fcb255e96949f", "increment()", maxTxSubmissionRetries)
errCh <- err
}

Expand Down Expand Up @@ -770,12 +771,12 @@ func TestSignerRenew(t *testing.T) {
addOracleFunctionSignature := "addOracle(address _oracle) external returns (uint256)"
removeOracleFunctionSignature := "function removeOracle(address _oracle) external"

err = chainHelperForCleanup.SubmitDelegatedFallbackDirect(ctx, contractAddr, addOracleFunctionSignature, common.HexToAddress(oldSignerAddr))
err = chainHelperForCleanup.SubmitDelegatedFallbackDirect(ctx, contractAddr, addOracleFunctionSignature, maxTxSubmissionRetries, common.HexToAddress(oldSignerAddr))
if err != nil {
t.Errorf("Unexpected error: %v", err)
}

err = chainHelperForCleanup.SubmitDelegatedFallbackDirect(ctx, contractAddr, removeOracleFunctionSignature, common.HexToAddress(newSignerAddr))
err = chainHelperForCleanup.SubmitDelegatedFallbackDirect(ctx, contractAddr, removeOracleFunctionSignature, maxTxSubmissionRetries, common.HexToAddress(newSignerAddr))
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion node/pkg/por/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/rs/zerolog/log"
)

const maxTxSubmissionRetries = 3

func New(ctx context.Context) (*App, error) {
// TODO: updates for multiple PORs
chain := os.Getenv("POR_CHAIN")
Expand Down Expand Up @@ -209,7 +211,7 @@ func (a *App) report(ctx context.Context, submissionValue float64, latestRoundId

latestRoundIdParam := new(big.Int).SetUint64(uint64(latestRoundId))

return a.KaiaHelper.SubmitDelegatedFallbackDirect(ctx, a.ContractAddress, SUBMIT_FUNCTION_STRING, latestRoundIdParam, submissionValueParam)
return a.KaiaHelper.SubmitDelegatedFallbackDirect(ctx, a.ContractAddress, SUBMIT_FUNCTION_STRING, maxTxSubmissionRetries, latestRoundIdParam, submissionValueParam)
}

func (a *App) DeviationCheck(oldValue float64, newValue float64) bool {
Expand Down
4 changes: 3 additions & 1 deletion node/pkg/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/rs/zerolog/log"
)

const maxTxSubmissionRetries = 3

func NewReporter(ctx context.Context, opts ...ReporterOption) (*Reporter, error) {
config := &ReporterConfig{
JobType: ReportJob,
Expand Down Expand Up @@ -135,7 +137,7 @@ func (r *Reporter) report(ctx context.Context, pairs map[string]SubmissionData)
wg.Add(1)
go func() {
defer wg.Done()
err := r.KaiaHelper.SubmitDelegatedFallbackDirect(ctx, r.contractAddress, SUBMIT_WITH_PROOFS, batchFeedHashes, batchValues, batchTimestamps, batchProofs)
err := r.KaiaHelper.SubmitDelegatedFallbackDirect(ctx, r.contractAddress, SUBMIT_WITH_PROOFS, maxTxSubmissionRetries, batchFeedHashes, batchValues, batchTimestamps, batchProofs)
if err != nil {
errorsChan <- err
}
Expand Down
7 changes: 4 additions & 3 deletions node/script/test_dal_consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
const (
// SINGLE_PAIR = "ADA-USDT"
// SUBMIT_WITH_PROOFS = "submit(bytes32[] calldata _feedHashes, int256[] calldata _answers, uint256[] calldata _timestamps, bytes[] calldata _proofs)"
SUBMIT_STRICT = "submitStrict(bytes32[] calldata _feedHashes, int256[] calldata _answers, uint256[] calldata _timestamps, bytes[] calldata _proofs)"
SUBMIT_STRICT = "submitStrict(bytes32[] calldata _feedHashes, int256[] calldata _answers, uint256[] calldata _timestamps, bytes[] calldata _proofs)"
maxTxSubmissionRetries = 3
)

func main() {
Expand Down Expand Up @@ -73,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, feedHashes, values, timestamps, proofs)
err = kaiaHelper.SubmitDelegatedFallbackDirect(ctx, contractAddr, SUBMIT_STRICT, maxTxSubmissionRetries, feedHashes, values, timestamps, proofs)
if err != nil {
log.Error().Err(err).Msg("MakeDirect")
panic(err)
Expand All @@ -86,7 +87,7 @@ func main() {
}
}

err = kaiaHelper.SubmitDelegatedFallbackDirect(ctx, contractAddr, SUBMIT_STRICT, feedHashes, values, timestamps, proofs)
err = kaiaHelper.SubmitDelegatedFallbackDirect(ctx, contractAddr, SUBMIT_STRICT, maxTxSubmissionRetries, feedHashes, values, timestamps, proofs)
if err != nil {
log.Error().Err(err).Msg("MakeDirect")
panic(err)
Expand Down
4 changes: 3 additions & 1 deletion node/script/test_submission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (
"github.com/rs/zerolog/log"
)

const maxTxSubmissionRetries = 3

func testContractFeeDelegatedCall(ctx context.Context, contractAddress string, contractFunction string, args ...interface{}) error {
kaiaHelper, err := helper.NewChainHelper(ctx)
if err != nil {
log.Error().Err(err).Msg("NewTxHelper")
return err
}

return kaiaHelper.SubmitDelegatedFallbackDirect(ctx, contractAddress, contractFunction, args...)
return kaiaHelper.SubmitDelegatedFallbackDirect(ctx, contractAddress, contractFunction, maxTxSubmissionRetries, args...)
}

func main() {
Expand Down

0 comments on commit 9d447e2

Please sign in to comment.