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

patch: do not fail in validate mint if tx is not found #15

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"os"
"strings"

log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -66,6 +67,9 @@ func validateConfig() {
if Config.Ethereum.PrivateKey == "" {
log.Fatal("[CONFIG] Ethereum.PrivateKey is required")
}
if strings.HasPrefix(Config.Ethereum.PrivateKey, "0x") {
Config.Ethereum.PrivateKey = Config.Ethereum.PrivateKey[2:]
}
if Config.Ethereum.WrappedPocketAddress == "" {
log.Fatal("[CONFIG] Ethereum.WrappedPocketAddress is required")
}
Expand Down
2 changes: 1 addition & 1 deletion eth/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (x *BurnMonitorRunner) SyncBlocks(startBlockNumber uint64, endBlockNumber u

func (x *BurnMonitorRunner) SyncTxs() bool {
if x.currentBlockNumber <= x.startBlockNumber {
log.Info("[BURN MONITOR] [MINT EXECUTOR] No new blocks to sync")
log.Info("[BURN MONITOR] No new blocks to sync")
return true
}

Expand Down
9 changes: 7 additions & 2 deletions eth/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ func (x *MintSignerRunner) ValidateMint(mint *models.Mint) (bool, error) {
return false, errors.New("Error fetching transaction: " + err.Error())
}

if tx.Tx == "" || tx.TxResult.Code != 0 {
log.Debug("[MINT SIGNER] Transaction not found or failed")
if tx == nil || tx.Tx == "" {
log.Debug("[MINT SIGNER] Transaction not found")
return false, errors.New("Transaction not found")
}

if tx.TxResult.Code != 0 {
log.Debug("[MINT SIGNER] Transaction failed")
return false, nil
}

Expand Down
17 changes: 13 additions & 4 deletions pokt/client/pokt_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func init() {

func queryRPC(path string, jsonArgs []byte) (string, error) {
cliURL := app.Config.Pocket.RPCURL + path
log.Debugln("[POKT] Querying RPC", cliURL)

req, err := http.NewRequest("POST", cliURL, bytes.NewBuffer(jsonArgs))
if err != nil {
Expand Down Expand Up @@ -157,12 +158,20 @@ func queryRPC(path string, jsonArgs []byte) (string, error) {
bz = []byte(res)
}

if resp.StatusCode == http.StatusOK {
// Check if the status code is 2XX
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
var prettyJSON bytes.Buffer
err = json.Indent(&prettyJSON, bz, "", " ")
if err == nil {
return prettyJSON.String(), nil
res := prettyJSON.String()
var obj RPCError
innerErr := json.Unmarshal([]byte(res), &obj)
if innerErr == nil && obj.Error.Code != 0 {
return "", fmt.Errorf("the rpc response returned an error: %+v", obj.Error)
}
return res, nil
}

return string(bz), nil
}
return "", fmt.Errorf("the http status code was not okay: %d, with a response of %+v", resp.StatusCode, resp)
Expand Down Expand Up @@ -222,9 +231,9 @@ func (c *pocketClient) getAccountTxsPerPage(address string, page uint32) (*Accou
params := rpc.PaginateAddrParams{
Address: address,
Page: int(page),
PerPage: 1000,
PerPage: 50,
Received: true,
Prove: true,
Prove: false,
Sort: "asc",
}
j, err := json.Marshal(params)
Expand Down
10 changes: 9 additions & 1 deletion pokt/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ type TxResult struct {
Code int64 `json:"code"`
Codespace string `json:"codespace"`
Data string `json:"data"`
Events string `json:"events"`
Info string `json:"info"`
Log string `json:"log"`
MessageType string `json:"message_type"`
Recipient string `json:"recipient"`
Signer string `json:"signer"`
}

type RPCError struct {
Jsonrpc string `json:"jsonrpc"`
Id string `json:"id"`
Error struct {
Code int64 `json:"code"`
Message string `json:"message"`
} `json:"error"`
}
19 changes: 19 additions & 0 deletions pokt/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (x *BurnExecutorRunner) HandleInvalidMint(doc *models.InvalidMint) bool {
return false
}

if res == nil || strings.TrimSpace(res.TransactionHash) == "" {
log.Error("[BURN EXECUTOR] Invalid mint return tx hash not found")
return false
}

filter = bson.M{
"_id": doc.Id,
"status": models.StatusSigned,
Expand All @@ -80,6 +85,10 @@ func (x *BurnExecutorRunner) HandleInvalidMint(doc *models.InvalidMint) bool {
log.Error("[BURN EXECUTOR] Error fetching transaction: ", err)
return false
}
if tx == nil || tx.Tx == "" {
log.Error("[BURN EXECUTOR] Invalid mint return tx not found: ", doc.ReturnTxHash)
return false
}

filter = bson.M{
"_id": doc.Id,
Expand Down Expand Up @@ -143,6 +152,11 @@ func (x *BurnExecutorRunner) HandleBurn(doc *models.Burn) bool {
return false
}

if res == nil || strings.TrimSpace(res.TransactionHash) == "" {
log.Error("[BURN EXECUTOR] Burn return tx hash not found")
return false
}

filter = bson.M{
"_id": doc.Id,
"status": models.StatusSigned,
Expand All @@ -163,6 +177,11 @@ func (x *BurnExecutorRunner) HandleBurn(doc *models.Burn) bool {
return false
}

if tx == nil || tx.Tx == "" {
log.Error("[BURN EXECUTOR] Burn return tx not found: ", doc.ReturnTxHash)
return false
}

filter = bson.M{
"_id": doc.Id,
"status": models.StatusSubmitted,
Expand Down
16 changes: 14 additions & 2 deletions pokt/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ func (x *BurnSignerRunner) ValidateInvalidMint(doc *models.InvalidMint) (bool, e
return false, errors.New("Error fetching transaction: " + err.Error())
}

if tx.Tx == "" || tx.TxResult.Code != 0 {
log.Debug("[BURN SIGNER] Transaction not found or failed")
if tx == nil || tx.Tx == "" {
return false, errors.New("Transaction not found")
}

if tx.TxResult.Code != 0 {
log.Debug("[BURN SIGNER] Transaction failed")
return false, nil
}

Expand Down Expand Up @@ -160,6 +164,10 @@ func (x *BurnSignerRunner) HandleInvalidMint(doc *models.InvalidMint) bool {
"updated_at": time.Now(),
},
}
if doc.Confirmations == "0" {
log.Debug("[BURN SIGNER] Invalid mint has no confirmations, skipping")
return false
}
} else {

if doc.Status == models.StatusConfirmed {
Expand Down Expand Up @@ -292,6 +300,10 @@ func (x *BurnSignerRunner) HandleBurn(doc *models.Burn) bool {
"updated_at": time.Now(),
},
}
if doc.Confirmations == "0" {
log.Debug("[BURN SIGNER] Burn has no confirmations, skipping")
return false
}
} else {

if doc.Status == models.StatusConfirmed {
Expand Down