From 3b2290d590a7182b1c72322cfc4957be4a90fe99 Mon Sep 17 00:00:00 2001 From: Augustus Chang Date: Thu, 13 Jun 2024 14:25:01 -0400 Subject: [PATCH 1/3] read pending block not latest --- relayer/pkg/starknet/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relayer/pkg/starknet/client.go b/relayer/pkg/starknet/client.go index 29ef1b03..9b473ea1 100644 --- a/relayer/pkg/starknet/client.go +++ b/relayer/pkg/starknet/client.go @@ -92,7 +92,7 @@ func (c *Client) CallContract(ctx context.Context, ops CallOps) (data []*felt.Fe Calldata: ops.Calldata, } - res, err := c.Call(ctx, tx, starknetrpc.WithBlockTag("latest")) + res, err := c.Call(ctx, tx, starknetrpc.WithBlockTag("pending")) if err != nil { return nil, fmt.Errorf("error in client.CallContract: %w", err) } From 7bf092e00c8012992876c57364eee32a2402a01d Mon Sep 17 00:00:00 2001 From: Augustus Chang Date: Thu, 13 Jun 2024 18:09:59 -0400 Subject: [PATCH 2/3] fix event parsing when reading from pending block --- relayer/pkg/chainlink/ocr2/client.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/relayer/pkg/chainlink/ocr2/client.go b/relayer/pkg/chainlink/ocr2/client.go index 797e988e..d1dd2783 100644 --- a/relayer/pkg/chainlink/ocr2/client.go +++ b/relayer/pkg/chainlink/ocr2/client.go @@ -185,7 +185,18 @@ func (c *Client) LinkAvailableForPayment(ctx context.Context, address *felt.Felt } func (c *Client) fetchEventsFromBlock(ctx context.Context, address *felt.Felt, eventType string, blockNum uint64) (events []starknetrpc.EmittedEvent, err error) { - block := starknetrpc.WithBlockNumber(blockNum) + latestBlockHeight, err := c.r.LatestBlockHeight(ctx) + if err != nil { + return nil, fmt.Errorf("couldn't fetch latest block height: %w", err) + } + + var block starknetrpc.BlockID + // "blockNum" may be available on-chain, but unqueryable via the RPC because the block is pending + if blockNum > latestBlockHeight { + block = starknetrpc.WithBlockTag("pending") + } else { + block = starknetrpc.WithBlockNumber(blockNum) + } eventKey := starknetutils.GetSelectorFromNameFelt(eventType) From 3904b93eb98964a0f432805ec6b8a3c47bfb04b3 Mon Sep 17 00:00:00 2001 From: Augustus Chang Date: Fri, 14 Jun 2024 10:20:57 -0400 Subject: [PATCH 3/3] lets go --- relayer/pkg/chainlink/ocr2/client_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/relayer/pkg/chainlink/ocr2/client_test.go b/relayer/pkg/chainlink/ocr2/client_test.go index b2161aaa..cbe84a17 100644 --- a/relayer/pkg/chainlink/ocr2/client_test.go +++ b/relayer/pkg/chainlink/ocr2/client_test.go @@ -47,6 +47,8 @@ func TestOCR2Client(t *testing.T) { require.NoError(t, json.Unmarshal(req, &call)) switch call.Method { + case "starknet_blockNumber": + out = []byte(`{"result":777}`) case "starknet_chainId": out = []byte(`{"result":"0x534e5f4d41494e"}`) case "starknet_call":