From 396ed2590f20d000a73d8eb9f0e05ac320bae55a Mon Sep 17 00:00:00 2001 From: dqnk <64268180+dqnk@users.noreply.github.com> Date: Mon, 2 Sep 2024 09:54:05 +0200 Subject: [PATCH] add reward UTXO request timeout --- utils/chain/p_chain_rpc_client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/chain/p_chain_rpc_client.go b/utils/chain/p_chain_rpc_client.go index c6a2a51..34fa576 100644 --- a/utils/chain/p_chain_rpc_client.go +++ b/utils/chain/p_chain_rpc_client.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "os" + "time" "github.com/ava-labs/avalanchego/api" "github.com/ava-labs/avalanchego/ids" @@ -13,6 +14,10 @@ import ( "github.com/ybbus/jsonrpc/v3" ) +const ( + RequestTimeout = 10 * time.Second +) + // Copy-paste from // // "github.com/ava-labs/avalanchego/vms/platformvm/service" @@ -45,7 +50,8 @@ func (c *AvalancheRPCClient) GetRewardUTXOs(id ids.ID) (*GetRewardUTXOsReply, er Encoding: formatting.Hex, } reply := &GetRewardUTXOsReply{} - ctx := context.Background() + ctx, cancelCtx := context.WithTimeout(context.Background(), RequestTimeout) + defer cancelCtx() response, err := c.client.Call(ctx, "platform.getRewardUTXOs", params) if err != nil { return nil, err