Skip to content

Commit

Permalink
replace GetRecentBlockhash with GetLatestBlockhash; add check on Vsiz…
Browse files Browse the repository at this point in the history
…e; misc
  • Loading branch information
ws4charlie committed Aug 27, 2024
1 parent 3916b96 commit 3780897
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion e2e/runner/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r *E2ERunner) CreateSignedTransaction(
privateKey solana.PrivateKey,
) *solana.Transaction {
// get a recent blockhash
recent, err := r.SolanaClient.GetRecentBlockhash(r.Ctx, rpc.CommitmentFinalized)
recent, err := r.SolanaClient.GetLatestBlockhash(r.Ctx, rpc.CommitmentFinalized)
require.NoError(r, err)

// create the initialize transaction
Expand Down
7 changes: 7 additions & 0 deletions zetaclient/chains/bitcoin/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
DynamicDepositorFeeHeight = 834500

// DynamicDepositorFeeHeightV2 is the mainnet height from which dynamic depositor fee V2 is applied
// Height 863400 is approximately a month away (2024-09-28) from the time of writing, allowing enough time for the upgrade
DynamicDepositorFeeHeightV2 = 863400
)

Expand Down Expand Up @@ -281,6 +282,12 @@ func CalcDepositorFeeV2(
// GetRecentFeeRate gets the highest fee rate from recent blocks
// Note: this method should be used for testnet ONLY
func GetRecentFeeRate(rpcClient interfaces.BTCRPCClient, netParams *chaincfg.Params) (uint64, error) {

Check warning on line 284 in zetaclient/chains/bitcoin/fee.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/fee.go#L284

Added line #L284 was not covered by tests
// should avoid using this method for mainnet
if netParams.Name == chaincfg.MainNetParams.Name {
return 0, errors.New("GetRecentFeeRate should not be used for mainnet")

Check warning on line 287 in zetaclient/chains/bitcoin/fee.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/fee.go#L286-L287

Added lines #L286 - L287 were not covered by tests
}

// get the current block number
blockNumber, err := rpcClient.GetBlockCount()
if err != nil {
return 0, err

Check warning on line 293 in zetaclient/chains/bitcoin/fee.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/fee.go#L291-L293

Added lines #L291 - L293 were not covered by tests
Expand Down
5 changes: 5 additions & 0 deletions zetaclient/chains/bitcoin/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func GetTransactionFeeAndRate(rpcClient interfaces.BTCRPCClient, rawResult *btcj
totalOutputValue int64
)

Check warning on line 131 in zetaclient/chains/bitcoin/rpc/rpc.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/rpc/rpc.go#L127-L131

Added lines #L127 - L131 were not covered by tests

// make sure the tx Vsize is not zero (should not happen)
if rawResult.Vsize <= 0 {
return 0, 0, fmt.Errorf("tx %s has non-positive Vsize: %d", rawResult.Txid, rawResult.Vsize)

Check warning on line 135 in zetaclient/chains/bitcoin/rpc/rpc.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/rpc/rpc.go#L134-L135

Added lines #L134 - L135 were not covered by tests
}

// sum up total input value
for _, vin := range rawResult.Vin {
prevTx, err := GetRawTxByHash(rpcClient, vin.Txid)

Check warning on line 140 in zetaclient/chains/bitcoin/rpc/rpc.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/rpc/rpc.go#L139-L140

Added lines #L139 - L140 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ type SolanaRPCClient interface {
account solana.PublicKey,
commitment solrpc.CommitmentType,
) (*solrpc.GetBalanceResult, error)
GetRecentBlockhash(ctx context.Context, commitment solrpc.CommitmentType) (*solrpc.GetRecentBlockhashResult, error)
GetLatestBlockhash(ctx context.Context, commitment solrpc.CommitmentType) (*solrpc.GetLatestBlockhashResult, error)
GetRecentPrioritizationFees(
ctx context.Context,
accounts solana.PublicKeySlice,
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/solana/signer/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func (signer *Signer) SignWithdrawTx(ctx context.Context, msg contracts.MsgWithd
attachWithdrawAccounts(&inst, privkey.PublicKey(), signer.pda, msg.To(), signer.gatewayID)

// get a recent blockhash
recent, err := signer.client.GetRecentBlockhash(ctx, rpc.CommitmentFinalized)
recent, err := signer.client.GetLatestBlockhash(ctx, rpc.CommitmentFinalized)

Check warning on line 72 in zetaclient/chains/solana/signer/withdraw.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/withdraw.go#L72

Added line #L72 was not covered by tests
if err != nil {
return nil, errors.Wrap(err, "GetRecentBlockhash error")
return nil, errors.Wrap(err, "GetLatestBlockhash error")

Check warning on line 74 in zetaclient/chains/solana/signer/withdraw.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/withdraw.go#L74

Added line #L74 was not covered by tests
}

// create a transaction that wraps the instruction
Expand Down
16 changes: 8 additions & 8 deletions zetaclient/testutils/mocks/solana_rpc.go

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

0 comments on commit 3780897

Please sign in to comment.