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

Open
wants to merge 104 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
2d1a82d
refactor so txm owns blockhash assignment
Farber98 Nov 15, 2024
50dfef0
lastValidBlockHeight shouldn't be exported
Farber98 Nov 15, 2024
4e545e2
better comment
Farber98 Nov 15, 2024
4ded53c
refactor sendWithRetry to make it clearer
Farber98 Nov 15, 2024
9e1be6d
confirm loop refactor
Farber98 Nov 18, 2024
7dd2028
fix infinite loop
Farber98 Nov 18, 2024
6c675f2
move accountID inside msg
Farber98 Nov 19, 2024
b0d9426
lint fix
Farber98 Nov 19, 2024
1b38665
base58 does not contain lower l
Farber98 Nov 19, 2024
6923ddf
fix hash errors
Farber98 Nov 19, 2024
462844b
fix generate random hash
Farber98 Nov 19, 2024
fd785d0
remove blockhash as we only need block height
Farber98 Nov 19, 2024
cf958a4
expired tx changes without tests
Farber98 Nov 19, 2024
c5e957b
add maybe to mocks
Farber98 Nov 19, 2024
a505993
expiration tests
Farber98 Nov 19, 2024
adc8b1c
send txes through queue
Farber98 Nov 19, 2024
7d77f99
revert pendingtx leakage of information. overwrite blockhash
Farber98 Nov 20, 2024
92a280b
fix order of confirm loop and not found signature check
Farber98 Nov 20, 2024
2598e19
fix mocks
Farber98 Nov 20, 2024
42b3da1
prevent confirmation loop to mark tx as errored when it needs to be r…
Farber98 Nov 20, 2024
89af1f3
fix test
Farber98 Nov 20, 2024
5e8a0da
fix pointer
Farber98 Nov 20, 2024
75c1dcd
add comments
Farber98 Nov 21, 2024
4ff2d23
reduce rpc calls + refactors
Farber98 Nov 21, 2024
84e423e
tests + check to save rpc calls
Farber98 Nov 21, 2024
7d8319e
address feedback + remove redundant impl
Farber98 Nov 22, 2024
68f3a3e
iface comment
Farber98 Nov 22, 2024
780179f
address feedback on compute unit limit and lastValidBlockHeight assig…
Farber98 Nov 25, 2024
98f0246
blockhash assignment inside txm.sendWithRetry
Farber98 Nov 25, 2024
cbf55f6
address feedback
Farber98 Nov 26, 2024
90daf33
Merge branch 'develop' into nonevm-706-support-custom-bumping-strateg…
Farber98 Nov 26, 2024
77b28cf
refactors after merge
Farber98 Nov 26, 2024
0c4a7d8
fix interactive rebase
Farber98 Nov 26, 2024
849ac48
fix whitespace diffs
Farber98 Nov 26, 2024
20a1548
fix import
Farber98 Nov 26, 2024
a4d4770
fix mocks
Farber98 Nov 26, 2024
56a64da
add on prebroadcaste error
Farber98 Nov 26, 2024
9148d7d
remove rebroadcast count and fix package
Farber98 Nov 27, 2024
caf2cbf
improve docs
Farber98 Nov 27, 2024
1fbd63f
Merge branch 'develop' into backup-branch-fee-bumping
Farber98 Nov 28, 2024
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
5c22af2
Merge branch 'develop' into backup-branch-fee-bumping
Farber98 Dec 5, 2024
02ffd1a
fix comparison against blockHeight instead of slotHeight
Farber98 Dec 5, 2024
c00494c
address feedback
Farber98 Dec 5, 2024
6ac30b0
fix lint
Farber98 Dec 5, 2024
36ee4ec
Merge branch 'develop' into backup-branch-fee-bumping
Farber98 Dec 5, 2024
0e38174
fix log
Farber98 Dec 5, 2024
d240021
address feedback
Farber98 Dec 6, 2024
4389e13
remove useless slot height
Farber98 Dec 6, 2024
23f42d1
address feedback
Farber98 Dec 6, 2024
6bcdd8f
Merge branch 'develop' into backup-branch-fee-bumping
Farber98 Dec 9, 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
50dd10f
address feedback
Farber98 Dec 10, 2024
34045ae
Merge branch 'backup-branch-fee-bumping' into nonevm-984-reorg
Farber98 Dec 10, 2024
10e5d9d
address feedback
Farber98 Dec 10, 2024
10b0453
Merge branch 'develop' into backup-branch-fee-bumping
Farber98 Dec 11, 2024
2ea0c50
validate that tx doesn't exist in any of maps when adding new tx
Farber98 Dec 11, 2024
b5a6927
Merge branch 'develop' into backup-branch-fee-bumping
Farber98 Dec 11, 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
dff36b0
Merge branch 'develop' into nonevm-984-reorg
Farber98 Dec 19, 2024
dbf4e41
rebroadcast with new blockhash + add integration tests
Farber98 Dec 23, 2024
d94a2c9
fix integration tests
Farber98 Dec 23, 2024
da1ee68
Merge branch 'develop' into nonevm-984-reorg
Farber98 Dec 23, 2024
6c08a75
Merge branch 'develop' into nonevm-984-reorg
Farber98 Jan 2, 2025
cc50224
remove unused params and better comments
Farber98 Jan 2, 2025
afa47a6
handle reorg equally for processed and confirmed at a sig level
Farber98 Jan 5, 2025
b087266
add comments and rename txHasReorg to IsTxReorged for better readability
Farber98 Jan 6, 2025
4047083
Merge branch 'develop' into nonevm-984-reorg
Farber98 Jan 6, 2025
ae95e4f
change test name to solve github CI failing check
Farber98 Jan 6, 2025
2515b7a
fix ci
Farber98 Jan 6, 2025
2826ad1
fix tests removing parallel
Farber98 Jan 6, 2025
71662e1
fix integration tests
Farber98 Jan 6, 2025
9987e41
capture range var
Farber98 Jan 6, 2025
145560f
address feedback
Farber98 Jan 7, 2025
ea4d0fa
address feedback
Farber98 Jan 7, 2025
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
Farber98 marked this conversation as resolved.
Show resolved Hide resolved
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