Skip to content

[BWS] Set latest nonce on publish for EVM proposals #3971

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 10 additions & 2 deletions packages/bitcore-wallet-service/src/lib/chain/eth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,15 @@ export class EthChain implements IChain {
return cb(null, 0);
}

refreshTxData(_server: WalletService, txp, _opts, cb) {
return cb(null, txp);
refreshTxData(server: WalletService, txp, opts, cb) {
// set latest nonce
server._getTransactionCount(opts.wallet, txp.from, (err, nonce) => {
if (err) return cb(err);
if (!Number(nonce)) {
return cb(new Error('Nonce is not a number'));
}
txp.nonce = nonce;
return cb(null, txp);
});
}
}
8 changes: 7 additions & 1 deletion packages/bitcore-wallet-service/src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,10 @@ export class WalletService implements IWalletService {
// SOL is skipped since its a non necessary field that is expected to be provided by the client.
if (!opts.nonce && !Constants.SVM_CHAINS[wallet.chain.toUpperCase()]) {
try {
if (Constants.EVM_CHAINS[wallet.chain.toUpperCase()]) {
// if nonce mangement is done by BWS, default to refreshing nonce on txp publish
opts.refreshOnPublish = true;
}
opts.nonce = await ChainService.getTransactionCount(this, wallet, opts.from);
} catch (error) {
return next(error);
Expand Down Expand Up @@ -2897,6 +2901,7 @@ export class WalletService implements IWalletService {
ChainService.checkTxUTXOs(this, txp, opts, err => {
if (err) return cb(err);
txp.status = 'pending';
opts.wallet = wallet;
ChainService.refreshTxData(this, txp, opts, (err, txp) => {
if (err) return cb(err);
if (txp.isRepublishEnabled() && !txp.prePublishRaw) {
Expand Down Expand Up @@ -3162,7 +3167,8 @@ export class WalletService implements IWalletService {

if (txp.signingMethod === 'schnorr' && !opts.supportBchSchnorr) return cb(Errors.UPGRADE_NEEDED);

if ([...Object.keys(Constants.EVM_CHAINS), 'XRP'].includes(wallet.chain.toUpperCase())) {
// Validate nonces only if they are not reset on signing via a re-publish
if ([...Object.keys(Constants.EVM_CHAINS), 'XRP'].includes(wallet.chain.toUpperCase()) && !txp.isRepublishEnabled()) {
try {
const txps = await this.getPendingTxsPromise({});
for (let t of txps) {
Expand Down