-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: benchmark tx size with fee (#5414)
This PR adds new benchmarks to compare tx size with different fee payment methods. The tx type chosen for this benchmark is a simple private transfer: `token_contract.transfer(alice, bob, 1n, 0)` . This is expected to (1) nullify one of Alice's note (2) create a note for Bob with the amount and (3) create a note for Alice with the left over from the nullified note. On top of this base we add the costs of paying the fee in public/private Fix #5403
- Loading branch information
Showing
10 changed files
with
141 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
AccountWalletWithPrivateKey, | ||
AztecAddress, | ||
FeePaymentMethod, | ||
NativeFeePaymentMethod, | ||
PrivateFeePaymentMethod, | ||
PublicFeePaymentMethod, | ||
TxStatus, | ||
} from '@aztec/aztec.js'; | ||
import { FPCContract, GasTokenContract, TokenContract } from '@aztec/noir-contracts.js'; | ||
import { getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token'; | ||
|
||
import { jest } from '@jest/globals'; | ||
|
||
import { EndToEndContext, publicDeployAccounts, setup } from '../fixtures/utils.js'; | ||
|
||
jest.setTimeout(50_000); | ||
|
||
describe('benchmarks/tx_size_fees', () => { | ||
let ctx: EndToEndContext; | ||
let aliceWallet: AccountWalletWithPrivateKey; | ||
let bobAddress: AztecAddress; | ||
let sequencerAddress: AztecAddress; | ||
let gas: GasTokenContract; | ||
let fpc: FPCContract; | ||
let token: TokenContract; | ||
|
||
// setup the environment | ||
beforeAll(async () => { | ||
ctx = await setup(3); | ||
aliceWallet = ctx.wallets[0]; | ||
bobAddress = ctx.wallets[1].getAddress(); | ||
sequencerAddress = ctx.wallets[2].getAddress(); | ||
|
||
await ctx.aztecNode.setConfig({ | ||
feeRecipient: sequencerAddress, | ||
}); | ||
|
||
await publicDeployAccounts(aliceWallet, ctx.accounts); | ||
}); | ||
|
||
// deploy the contracts | ||
beforeAll(async () => { | ||
gas = await GasTokenContract.at( | ||
getCanonicalGasTokenAddress(ctx.deployL1ContractsValues.l1ContractAddresses.gasPortalAddress), | ||
aliceWallet, | ||
); | ||
token = await TokenContract.deploy(aliceWallet, aliceWallet.getAddress(), 'test', 'test', 18).send().deployed(); | ||
fpc = await FPCContract.deploy(aliceWallet, token.address, gas.address).send().deployed(); | ||
}); | ||
|
||
// mint tokens | ||
beforeAll(async () => { | ||
await Promise.all([ | ||
gas.methods.mint_public(aliceWallet.getAddress(), 1000n).send().wait(), | ||
token.methods.privately_mint_private_note(1000n).send().wait(), | ||
token.methods.mint_public(aliceWallet.getAddress(), 1000n).send().wait(), | ||
|
||
gas.methods.mint_public(fpc.address, 1000n).send().wait(), | ||
]); | ||
}); | ||
|
||
it.each<() => Promise<FeePaymentMethod | undefined>>([ | ||
() => Promise.resolve(undefined), | ||
() => NativeFeePaymentMethod.create(aliceWallet), | ||
() => Promise.resolve(new PublicFeePaymentMethod(token.address, fpc.address, aliceWallet)), | ||
() => Promise.resolve(new PrivateFeePaymentMethod(token.address, fpc.address, aliceWallet)), | ||
])('sends a tx with a fee', async createPaymentMethod => { | ||
const paymentMethod = await createPaymentMethod(); | ||
const tx = await token.methods | ||
.transfer(aliceWallet.getAddress(), bobAddress, 1n, 0) | ||
.send({ | ||
fee: paymentMethod | ||
? { | ||
maxFee: 3n, | ||
paymentMethod, | ||
} | ||
: undefined, | ||
}) | ||
.wait(); | ||
|
||
expect(tx.status).toEqual(TxStatus.MINED); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters