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

[NONEVM-984][solana] - Reorg Detection + lighter rpc call #951

Draft
wants to merge 35 commits into
base: backup-branch-fee-bumping
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bdf3457
track status on each signature to detect reorgs
Farber98 Nov 28, 2024
3ad2bc8
move things arround + add reorg detection
Farber98 Nov 29, 2024
4fd327a
linting errors
Farber98 Nov 29, 2024
2b29c33
fix some state tracking instances
Farber98 Nov 29, 2024
a6ce47b
remove redundant sig update
Farber98 Nov 30, 2024
3a6e643
move state from txes to sigs
Farber98 Nov 30, 2024
f4c6069
fix listAllExpiredBroadcastedTxs
Farber98 Nov 30, 2024
f027aeb
handle reorg after confirm cycle
Farber98 Nov 30, 2024
8c18891
associate sigs to retry ctx
Farber98 Dec 2, 2024
2902ec0
remove unused ctx
Farber98 Dec 2, 2024
1c1f723
add errored state and remove finalized
Farber98 Dec 2, 2024
6bc0c62
comment
Farber98 Dec 2, 2024
05442b2
Revert "comment"
Farber98 Dec 3, 2024
9b27a5b
Revert "remove unused ctx"
Farber98 Dec 3, 2024
ee14b60
Revert "associate sigs to retry ctx"
Farber98 Dec 3, 2024
d1f1ae7
Revert "fix listAllExpiredBroadcastedTxs"
Farber98 Dec 3, 2024
8911df2
Revert "move state from txes to sigs"
Farber98 Dec 3, 2024
52ce0e9
fix tx state
Farber98 Dec 3, 2024
fbbe978
address feedback
Farber98 Dec 3, 2024
cef6a91
fix ci
Farber98 Dec 3, 2024
3b3a71b
fix lint
Farber98 Dec 3, 2024
ef782c3
handle multiple sigs case
Farber98 Dec 4, 2024
08b0c6e
improve comment
Farber98 Dec 4, 2024
63a5f3f
improve logic and comments
Farber98 Dec 4, 2024
23f42d1
address feedback
Farber98 Dec 6, 2024
4a20622
Merge branch 'backup-branch-fee-bumping' into nonevm-984-reorg
Farber98 Dec 9, 2024
53948e1
add comment
Farber98 Dec 9, 2024
fdc8068
tests and fix some bugs
Farber98 Dec 9, 2024
34045ae
Merge branch 'backup-branch-fee-bumping' into nonevm-984-reorg
Farber98 Dec 10, 2024
10e5d9d
address feedback
Farber98 Dec 10, 2024
0a4b5aa
Merge branch 'backup-branch-fee-bumping' into nonevm-984-reorg
Farber98 Dec 12, 2024
5b34579
Merge branch 'backup-branch-fee-bumping' into nonevm-984-reorg
Farber98 Dec 12, 2024
17769f7
get height instead of whole block optimization
Farber98 Dec 12, 2024
d6fb891
fix mocks on expiration
Farber98 Dec 12, 2024
b6f4729
fix test
Farber98 Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/solana/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Reader interface {
ChainID(ctx context.Context) (mn.StringID, error)
GetFeeForMessage(ctx context.Context, msg string) (uint64, error)
GetLatestBlock(ctx context.Context) (*rpc.GetBlockResult, error)
// GetLatestBlockHeight returns the latest block height of the node based on the configured commitment type
GetLatestBlockHeight(ctx context.Context) (uint64, error)
GetTransaction(ctx context.Context, txHash solana.Signature, opts *rpc.GetTransactionOpts) (*rpc.GetTransactionResult, error)
GetBlocks(ctx context.Context, startSlot uint64, endSlot *uint64) (rpc.BlocksResult, error)
GetBlocksWithLimit(ctx context.Context, startSlot uint64, limit uint64) (*rpc.BlocksResult, error)
Expand Down Expand Up @@ -331,6 +333,19 @@ func (c *Client) GetLatestBlock(ctx context.Context) (*rpc.GetBlockResult, error
return v.(*rpc.GetBlockResult), err
}

// GetLatestBlockHeight returns the latest block height of the node based on the configured commitment type
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is out of scope of the reorg, but pushing it here so we don't need to make a separate merge: smartcontract-it.atlassian.net/browse/NONEVM-1015

func (c *Client) GetLatestBlockHeight(ctx context.Context) (uint64, error) {
done := c.latency("latest_block_height")
defer done()
ctx, cancel := context.WithTimeout(ctx, c.txTimeout)
defer cancel()

v, err, _ := c.requestGroup.Do("GetBlockHeight", func() (interface{}, error) {
return c.rpc.GetBlockHeight(ctx, c.commitment)
})
return v.(uint64), err
}

func (c *Client) GetBlock(ctx context.Context, slot uint64) (*rpc.GetBlockResult, error) {
// get block based on slot
done := c.latency("get_block")
Expand Down
32 changes: 32 additions & 0 deletions pkg/solana/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ func TestClient_Reader_Integration(t *testing.T) {
assert.GreaterOrEqual(t, slot, startSlot)
assert.LessOrEqual(t, slot, slot0)
}

// GetLatestBlockHeight
// Test fetching the latest block height
blockHeight, err := c.GetLatestBlockHeight(ctx)
require.NoError(t, err)
require.Greater(t, blockHeight, uint64(0), "Block height should be greater than 0")
}

func TestClient_Reader_ChainID(t *testing.T) {
Expand Down Expand Up @@ -288,6 +294,32 @@ func TestClient_GetBlocks(t *testing.T) {
requestTimeout, 500*time.Millisecond)
}

func TestClient_GetLatestBlockHeight(t *testing.T) {
t.Parallel()

ctx := tests.Context(t)
url := SetupLocalSolNode(t)
requestTimeout := 5 * time.Second
lggr := logger.Test(t)
cfg := config.NewDefault()

// Initialize the client
c, err := NewClient(url, cfg, requestTimeout, lggr)
require.NoError(t, err)

// Get the latest block height
blockHeight, err := c.GetLatestBlockHeight(ctx)
require.NoError(t, err)
require.Greater(t, blockHeight, uint64(0), "Block height should be greater than 0")

// Wait until the block height increases
require.Eventually(t, func() bool {
newBlockHeight, err := c.GetLatestBlockHeight(ctx)
require.NoError(t, err)
return newBlockHeight > blockHeight
}, 10*time.Second, 1*time.Second, "Block height should eventually increase")
}

func TestClient_SendTxDuplicates_Integration(t *testing.T) {
ctx := tests.Context(t)
// set up environment
Expand Down
56 changes: 56 additions & 0 deletions pkg/solana/client/mocks/reader_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading