Skip to content

Commit

Permalink
Re-introducing txdao changes (#1037)
Browse files Browse the repository at this point in the history
* Revert "Revert "Remove to/from from txdao, replace with 'origin' (#1024)""

This reverts commit cd7d823.

* test: updated snapshot
  • Loading branch information
benesjan authored Jul 12, 2023
1 parent d3ac967 commit 7599ea9
Show file tree
Hide file tree
Showing 28 changed files with 67 additions and 85 deletions.
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, TxRequest<NCT> con

template <typename NCT> std::ostream& operator<<(std::ostream& os, TxRequest<NCT> const& tx_request)
{
return os << "from: " << tx_request.origin << "\n"
return os << "origin: " << tx_request.origin << "\n"
<< "function_data: " << tx_request.function_data << "\n"
<< "args_hash: " << tx_request.args_hash << "\n"
<< "tx_context: " << tx_request.tx_context << "\n";
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ async function main() {
const client = createAztecRpcClient(options.rpcUrl);
const wallet = await getAccountWallet(client, Buffer.from(options.privateKey, 'hex'), accountCreationSalt);
const contract = new Contract(contractAddress, contractAbi, wallet);
const from = (await wallet.getAccounts()).find(addr => addr.equals(wallet.getAddress()));
const origin = (await wallet.getAccounts()).find(addr => addr.equals(wallet.getAddress()));
const tx = contract.methods[functionName](...functionArgs).send({
from,
origin,
});
await tx.isMined();
log('\nTX has been mined');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('Account State', () => {
expect(txs).toEqual([
expect.objectContaining({
blockNumber: 1,
from: ownerAddress,
origin: ownerAddress,
}),
]);
expect(addNoteSpendingInfoBatchSpy).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -134,15 +134,15 @@ describe('Account State', () => {
expect(txs).toEqual([
expect.objectContaining({
blockNumber: 2,
from: ownerAddress,
origin: ownerAddress,
}),
expect.objectContaining({
blockNumber: 5,
from: ownerAddress,
origin: ownerAddress,
}),
expect.objectContaining({
blockNumber: 5,
from: ownerAddress,
origin: ownerAddress,
}),
]);
expect(addNoteSpendingInfoBatchSpy).toHaveBeenCalledTimes(1);
Expand Down
7 changes: 2 additions & 5 deletions yarn-project/aztec-rpc/src/account_state/account_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,12 @@ export class AccountState {
const { newContractData } = blockContext.block.getTx(txIndex);
const isContractDeployment = !newContractData[0].contractAddress.isZero();
const noteSpendingInfo = noteSpendingInfoDaos[j];
const [to, contractAddress] = isContractDeployment
? [undefined, noteSpendingInfo.contractAddress]
: [noteSpendingInfo.contractAddress, undefined];
const contractAddress = isContractDeployment ? noteSpendingInfo.contractAddress : undefined;
txDaos.push({
txHash,
blockHash: blockContext.getBlockHash(),
blockNumber: blockContext.block.number,
from: this.address,
to,
origin: this.address,
contractAddress,
error: '',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ export class AztecRPCServer implements AztecRPC {
await this.db.addTx(
TxDao.from({
txHash: await tx.getTxHash(),
from: account.getAddress(),
to: account.getAddress(),
origin: account.getAddress(),
contractAddress: deployedContractAddress,
}),
);
Expand Down Expand Up @@ -270,8 +269,7 @@ export class AztecRPCServer implements AztecRPC {
txHash: txHash,
blockHash: localTx?.blockHash,
blockNumber: localTx?.blockNumber,
from: localTx?.from,
to: localTx?.to,
origin: localTx?.origin,
contractAddress: localTx?.contractAddress,
error: '',
};
Expand All @@ -294,7 +292,7 @@ export class AztecRPCServer implements AztecRPC {
// if the transaction mined it will be removed from the pending pool and there is a race condition here as the synchroniser will not have the tx as mined yet, so it will appear dropped
// until the synchroniser picks this up

const accountState = this.synchroniser.getAccount(localTx.from);
const accountState = this.synchroniser.getAccount(localTx.origin);
if (accountState && !(await accountState?.isSynchronised())) {
// there is a pending L2 block, which means the transaction will not be in the tx pool but may be awaiting mine on L1
return {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-rpc/src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface GetOptions {
*/
export interface Database extends ContractDatabase {
getTx(txHash: TxHash): Promise<TxDao | undefined>;
getTxsByAddress(from: AztecAddress): Promise<TxDao[]>;
getTxsByAddress(origin: AztecAddress): Promise<TxDao[]>;
addTx(tx: TxDao): Promise<void>;
addTxs(txs: TxDao[]): Promise<void>;

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec-rpc/src/database/memory_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
/**
* Retrieve all transactions associated with a given AztecAddress.
*
* @param from - The sender's address.
* @param origin - The sender's address.
* @returns A Promise resolving to an array of TxDao objects associated with the sender.
*/
public getTxsByAddress(from: AztecAddress) {
return Promise.resolve(this.txTable.filter(tx => tx.from.equals(from)));
public getTxsByAddress(origin: AztecAddress) {
return Promise.resolve(this.txTable.filter(tx => tx.origin.equals(origin)));
}

/**
Expand Down
13 changes: 3 additions & 10 deletions yarn-project/aztec-rpc/src/database/tx_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export class TxDao {
/**
* The sender's Aztec address.
*/
public readonly from: AztecAddress,
/**
* The contract address involved in the transaction. Undefined if the transaction is for deployinig a new contract.
*/
public readonly to: AztecAddress | undefined,
public readonly origin: AztecAddress,
/**
* The address of the contract deployed by the transaction. Undefined if the transaction does not deploy a new contract.
*/
Expand Down Expand Up @@ -53,9 +49,7 @@ export class TxDao {
/** The block number in which the transaction was included. */
blockNumber?: number | undefined;
/** The sender's Aztec address. */
from: AztecAddress;
/** The contract address involved in the transaction. Undefined if the transaction is for deployinig a new contract. */
to: AztecAddress | undefined;
origin: AztecAddress;
/** The address of the contract deployed by the transaction. Undefined if the transaction does not deploy a new contract. */
contractAddress: AztecAddress | undefined;
/** Description of any error encountered during the transaction. */
Expand All @@ -67,8 +61,7 @@ export class TxDao {
args.txHash,
args.blockHash,
args.blockNumber,
args.from,
args.to,
args.origin,
args.contractAddress,
args.error,
args.contractBytecode,
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ export class Synchroniser {
throw new Error(`Transaction ${txHash} not found in RPC database`);
}

const account = this.getAccount(tx.from);
const account = this.getAccount(tx.origin);
if (!account) {
throw new Error(`Unauthorised account: ${tx.from}`);
throw new Error(`Unauthorised account: ${tx.origin}`);
}

return tx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const transferWethOnL2 = async (
(await aztecRpcClient.getAccountPublicKey(ownerAddress)).toBigInts(),
(await aztecRpcClient.getAccountPublicKey(receiver)).toBigInts(),
)
.send({ from: ownerAddress });
.send({ origin: ownerAddress });
await transferTx.isMined(0, 0.5);
const transferReceipt = await transferTx.getReceipt();
// expect(transferReceipt.status).toBe(TxStatus.MINED);
Expand Down Expand Up @@ -240,7 +240,7 @@ async function main() {
// Call the mint tokens function on the noir contract
const consumptionTx = wethL2Contract.methods
.mint(wethAmountToBridge, ownerPub, owner, messageKey, secret, ethAccount.toField())
.send({ from: owner });
.send({ origin: owner });
await consumptionTx.isMined(0, 0.5);
const consumptionReceipt = await consumptionTx.getReceipt();
// expect(consumptionReceipt.status).toBe(TxStatus.MINED);
Expand Down Expand Up @@ -275,7 +275,7 @@ async function main() {
uniswapPortalAddress,
ethAccount.toField(),
)
.send({ from: owner });
.send({ origin: owner });
await withdrawTx.isMined(0, 0.5);
const withdrawReceipt = await withdrawTx.getReceipt();
// expect(withdrawReceipt.status).toBe(TxStatus.MINED);
Expand Down Expand Up @@ -326,7 +326,7 @@ async function main() {
// Call the mint tokens function on the noir contract
const daiMintTx = daiL2Contract.methods
.mint(daiAmountToBridge, ownerPub, owner, depositDaiMessageKey, secret, ethAccount.toField())
.send({ from: owner });
.send({ origin: owner });
await daiMintTx.isMined(0, 0.5);
const daiMintTxReceipt = await daiMintTx.getReceipt();
// expect(daiMintTxReceipt.status).toBe(TxStatus.MINED);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-sandbox/src/examples/zk_token_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function main() {

// Mint more tokens
logger(`Minting ${SECONDARY_AMOUNT} more coins`);
const mintTx = zkContract.methods.mint(SECONDARY_AMOUNT, ownerPubKeyPoint.toBigInts()).send({ from: ownerAddress });
const mintTx = zkContract.methods.mint(SECONDARY_AMOUNT, ownerPubKeyPoint.toBigInts()).send({ origin: ownerAddress });
await mintTx.isMined(0, 0.5);
const balanceAfterMint = await getBalance(zkContract, ownerPubKeyPoint, ownerAddress);
logger(`Owner's balance is now: ${balanceAfterMint}`);
Expand All @@ -74,7 +74,7 @@ async function main() {
logger(`Transferring ${SECONDARY_AMOUNT} tokens from owner to another account.`);
const transferTx = zkContract.methods
.transfer(SECONDARY_AMOUNT, ownerPubKeyPoint.toBigInts(), address2PubKeyPoint.toBigInts())
.send({ from: ownerAddress });
.send({ origin: ownerAddress });
await transferTx.isMined(0, 0.5);
const balanceAfterTransfer = await getBalance(zkContract, ownerPubKeyPoint, ownerAddress);
const receiverBalance = await getBalance(zkContract, address2PubKeyPoint, address2);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Contract } from '@aztec/aztec.js';
const contract = new Contract(contractAddress, contractAbi, aztecRpcServer);
const tx = contract.methods
.transfer(amount, recipientAddress))
.send({ from: senderAddress });
.send({ origin: senderAddress });
await tx.isMined();
console.log(`Transferred ${amount} to ${recipientAddress}!`);
```
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Contract Class', () => {
const param0 = 12;
const param1 = 345n;
const sentTx = fooContract.methods.bar(param0, param1).send({
from: account,
origin: account,
});
const txHash = await sentTx.getTxHash();
const receipt = await sentTx.getReceipt();
Expand All @@ -128,7 +128,7 @@ describe('Contract Class', () => {
const fooContract = new Contract(contractAddress, defaultAbi, wallet);
expect(() =>
fooContract.methods.qux().send({
from: account,
origin: account,
}),
).toThrow();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface SendMethodOptions {
/**
* Sender's address initiating the transaction.
*/
from?: AztecAddress;
origin?: AztecAddress;
/**
* The nonce representing the order of transactions sent by the address.
*/
Expand Down Expand Up @@ -60,7 +60,7 @@ export class ContractFunctionInteraction {
throw new Error("Can't call `create` on an unconstrained function.");
}
if (!this.txRequest) {
const executionRequest = this.getExecutionRequest(this.contractAddress, options.from);
const executionRequest = this.getExecutionRequest(this.contractAddress, options.origin);
const nodeInfo = await this.wallet.getNodeInfo();
const txContext = TxContext.empty(new Fr(nodeInfo.chainId), new Fr(nodeInfo.version));
const txRequest = await this.wallet.createAuthenticatedTxRequest([executionRequest], txContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe.skip('Contract Deployer', () => {
const sentTx = deployer.deploy(args[0], args[1]).send({
portalContract,
contractAddressSalt,
from: account,
origin: account,
});
const txHash = await sentTx.getTxHash();
const receipt = await sentTx.getReceipt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ vk_path: [ 0x1000 0x1001 0x1002 ]

exports[`structs/kernel serializes and prints private_kernel_inputs_init 1`] = `
"tx_request:
from: 0x1
origin: 0x1
function_data: function_selector: 257
is_private: 1
is_constructor: 1
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/end-to-end/src/cross_chain/test_harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class CrossChainTestHarness {
(await this.aztecRpcServer.getAccountPublicKey(this.ownerAddress)).toBigInts(),
(await this.aztecRpcServer.getAccountPublicKey(this.receiver)).toBigInts(),
)
.send({ from: this.accounts[0] });
.send({ origin: this.accounts[0] });

await transferTx.isMined(0, 0.1);
const transferReceipt = await transferTx.getReceipt();
Expand All @@ -171,7 +171,7 @@ export class CrossChainTestHarness {
// Call the mint tokens function on the noir contract
const consumptionTx = this.l2Contract.methods
.mint(bridgeAmount, this.ownerPub, this.ownerAddress, messageKey, secret, this.ethAccount.toField())
.send({ from: this.ownerAddress });
.send({ origin: this.ownerAddress });

await consumptionTx.isMined(0, 0.1);
const consumptionReceipt = await consumptionTx.getReceipt();
Expand All @@ -183,7 +183,7 @@ export class CrossChainTestHarness {
// Call the mint tokens function on the noir contract
const consumptionTx = this.l2Contract.methods
.mintPublic(bridgeAmount, this.ownerAddress, messageKey, secret, this.ethAccount.toField())
.send({ from: this.ownerAddress });
.send({ origin: this.ownerAddress });

await consumptionTx.isMined(0, 0.1);
const consumptionReceipt = await consumptionTx.getReceipt();
Expand Down Expand Up @@ -257,7 +257,7 @@ export class CrossChainTestHarness {

async shieldFundsOnL2(shieldAmount: bigint, secretHash: Fr) {
this.logger('Shielding funds on L2');
const shieldTx = this.l2Contract.methods.shield(shieldAmount, secretHash).send({ from: this.ownerAddress });
const shieldTx = this.l2Contract.methods.shield(shieldAmount, secretHash).send({ origin: this.ownerAddress });
await shieldTx.isMined(0, 0.1);
const shieldReceipt = await shieldTx.getReceipt();
expect(shieldReceipt.status).toBe(TxStatus.MINED);
Expand All @@ -267,7 +267,7 @@ export class CrossChainTestHarness {
this.logger('Spending commitment in private call');
const privateTx = this.l2Contract.methods
.redeemShield(shieldAmount, secret, this.ownerPub)
.send({ from: this.ownerAddress });
.send({ origin: this.ownerAddress });

await privateTx.isMined();
const privateReceipt = await privateTx.getReceipt();
Expand All @@ -279,7 +279,7 @@ export class CrossChainTestHarness {
this.logger('Unshielding tokens');
const unshieldTx = this.l2Contract.methods
.unshieldTokens(unshieldAmount, this.ownerPub, this.ownerAddress.toField())
.send({ from: this.ownerAddress });
.send({ origin: this.ownerAddress });
await unshieldTx.isMined();
const unshieldReceipt = await unshieldTx.getReceipt();

Expand Down
12 changes: 6 additions & 6 deletions yarn-project/end-to-end/src/e2e_account_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ describe('e2e_account_contract', () => {
await deployAll();

logger('Calling private function...');
const tx1 = child.methods.value(42).send({ from: schnorrAccountContractAddress });
const tx2 = childContractWithEcdsaSigning.methods.value(56).send({ from: ecdsaAccountContractAddress });
const tx1 = child.methods.value(42).send({ origin: schnorrAccountContractAddress });
const tx2 = childContractWithEcdsaSigning.methods.value(56).send({ origin: ecdsaAccountContractAddress });

const txs = [tx1, tx2];

Expand All @@ -151,8 +151,8 @@ describe('e2e_account_contract', () => {
await deployAll();

logger('Calling public function...');
const tx1 = child.methods.pubStoreValue(42).send({ from: schnorrAccountContractAddress });
const tx2 = childContractWithEcdsaSigning.methods.pubStoreValue(15).send({ from: ecdsaAccountContractAddress });
const tx1 = child.methods.pubStoreValue(42).send({ origin: schnorrAccountContractAddress });
const tx2 = childContractWithEcdsaSigning.methods.pubStoreValue(15).send({ origin: ecdsaAccountContractAddress });

const txs = [tx1, tx2];

Expand All @@ -179,7 +179,7 @@ describe('e2e_account_contract', () => {
await schnorrWallet.getAccountPublicKey(schnorrAccountContractAddress),
schnorrWallet,
);
await expect(child.methods.value(42).simulate({ from: schnorrAccountContractAddress })).rejects.toThrowError(
await expect(child.methods.value(42).simulate({ origin: schnorrAccountContractAddress })).rejects.toThrowError(
/could not satisfy all constraints/,
);
}, 60_000);
Expand All @@ -195,7 +195,7 @@ describe('e2e_account_contract', () => {
);
logger('Deploying child contract...');
child = await deployChildContract(await ecdsaWallet.getAccountPublicKey(ecdsaAccountContractAddress), ecdsaWallet);
await expect(child.methods.value(42).simulate({ from: ecdsaAccountContractAddress })).rejects.toThrowError(
await expect(child.methods.value(42).simulate({ origin: ecdsaAccountContractAddress })).rejects.toThrowError(
/could not satisfy all constraints/,
);
}, 60_000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('e2e_cross_chain_messaging', () => {
logger('Send L2 tx to withdraw funds');
const withdrawTx = l2Contract.methods
.withdraw(withdrawAmount, ownerPub, ethAccount, EthAddress.ZERO.toField())
.send({ from: ownerAddress });
.send({ origin: ownerAddress });

await withdrawTx.isMined(0, 0.1);
const withdrawReceipt = await withdrawTx.getReceipt();
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/end-to-end/src/e2e_deploy_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ describe('e2e_deploy_contract', () => {
const receipt = await tx.getReceipt();
expect(receipt).toEqual(
expect.objectContaining({
from: accounts[0],
to: accounts[0],
origin: accounts[0],
status: TxStatus.PENDING,
error: '',
}),
Expand Down
Loading

0 comments on commit 7599ea9

Please sign in to comment.