Remove redundant args from dispatch event (#527)

pull/547/head
Asa Oines 3 years ago committed by GitHub
parent 29970fe326
commit 165f60e622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      solidity/core/contracts/Outbox.sol
  2. 4
      solidity/core/test/outbox.test.ts
  3. 12
      typescript/hardhat/src/TestCoreApp.ts
  4. 1
      typescript/sdk/src/core/index.ts
  5. 38
      typescript/sdk/src/core/message.ts
  6. 1
      typescript/sdk/src/index.ts
  7. 8
      typescript/utils/src/types.ts
  8. 19
      typescript/utils/src/utils.ts

@ -73,17 +73,10 @@ contract Outbox is IOutbox, Version0, MerkleTreeManager, Mailbox {
/**
* @notice Emitted when a new message is dispatched via Abacus
* @param messageHash Hash of message; the leaf inserted to the Merkle tree for the message
* @param leafIndex Index of message's leaf in merkle tree
* @param destination Destination domain
* @param message Raw bytes of message
*/
event Dispatch(
bytes32 indexed messageHash,
uint256 indexed leafIndex,
uint32 indexed destination,
bytes message
);
event Dispatch(uint256 indexed leafIndex, bytes message);
event Fail();
@ -140,8 +133,7 @@ contract Outbox is IOutbox, Version0, MerkleTreeManager, Mailbox {
abi.encodePacked(_message, _leafIndex)
);
tree.insert(_messageHash);
// Emit Dispatch event with message information
emit Dispatch(_messageHash, _leafIndex, _destinationDomain, _message);
emit Dispatch(_leafIndex, _message);
return _leafIndex;
}

@ -89,7 +89,7 @@ describe('Outbox', async () => {
});
it('Dispatches a message', async () => {
const { message, destDomain, abacusMessage, leafIndex, hash } =
const { message, destDomain, abacusMessage, leafIndex } =
await testMessageValues();
// Send message with signer address as msg.sender
@ -103,7 +103,7 @@ describe('Outbox', async () => {
),
)
.to.emit(outbox, 'Dispatch')
.withArgs(hash, leafIndex, destDomain, abacusMessage);
.withArgs(leafIndex, abacusMessage);
});
it('Returns the leaf index of the dispatched message', async () => {

@ -11,7 +11,7 @@ import {
TestChainNames,
chainMetadata,
} from '@abacus-network/sdk';
import { types } from '@abacus-network/utils';
import { types, utils } from '@abacus-network/utils';
import { ethers } from 'ethers';
type MockProxyAddresses = {
@ -68,7 +68,8 @@ export class TestCoreApp extends AbacusCore<TestChainNames> {
const dispatchFilter = outbox.filters.Dispatch();
const dispatches = await outbox.queryFilter(dispatchFilter);
for (const dispatch of dispatches) {
const destination = dispatch.args.destination;
const message = utils.parseMessage(dispatch.args.message);
const destination = message.destination;
if (destination === chainMetadata[origin].id) {
throw new Error('Dispatched message to local domain');
}
@ -76,7 +77,12 @@ export class TestCoreApp extends AbacusCore<TestChainNames> {
const inbox: TestInbox =
// @ts-ignore
this.getContracts(destinationChain).inboxes[origin].inbox.contract;
const status = await inbox.messages(dispatch.args.messageHash);
const status = await inbox.messages(
utils.messageHash(
dispatch.args.message,
dispatch.args.leafIndex.toNumber(),
),
);
if (status !== types.MessageStatus.PROCESSED) {
const response = await inbox.testProcess(
dispatch.args.message,

@ -15,7 +15,6 @@ export {
AbacusMessage,
AbacusStatus,
MessageStatus,
parseMessage,
resolveDomain,
resolveId,
resolveNetworks,

@ -1,10 +1,10 @@
import { AbacusCore } from '.';
import { TransactionReceipt } from '@ethersproject/abstract-provider';
import { BigNumber } from '@ethersproject/bignumber';
import { arrayify, hexlify } from '@ethersproject/bytes';
import { keccak256 } from 'ethers/lib/utils';
import { Inbox, Outbox, Outbox__factory } from '@abacus-network/core';
import { types, utils } from '@abacus-network/utils';
import { Annotated, findAnnotatedSingleEvent } from '../events';
import { MultiProvider } from '../provider';
@ -24,15 +24,6 @@ import {
ProcessEvent,
} from './events';
// I didn't want to override the existing ParsedMessage in message.ts as that would include having to type AbacusMessage and more and it's not clear to me that we will keep those.
type ParsedMessage = {
origin: number;
sender: string;
destination: number;
recipient: string;
body: string;
};
export const resolveDomain = (nameOrDomain: NameOrDomain): ChainName =>
typeof nameOrDomain === 'number'
? DomainIdToChainName[nameOrDomain]
@ -44,7 +35,7 @@ export const resolveId = (nameOrDomain: NameOrDomain): number =>
: nameOrDomain;
export const resolveNetworks = (
message: ParsedMessage,
message: types.ParsedMessage,
): { origin: ChainName; destination: ChainName } => {
return {
origin: resolveDomain(message.origin),
@ -74,22 +65,6 @@ export type EventCache = {
process?: AnnotatedProcess;
};
/**
* Parse a serialized Abacus message from raw bytes.
*
* @param message
* @returns
*/
export function parseMessage(message: string): ParsedMessage {
const buf = Buffer.from(arrayify(message));
const origin = buf.readUInt32BE(0);
const sender = hexlify(buf.slice(4, 36));
const destination = buf.readUInt32BE(36);
const recipient = hexlify(buf.slice(40, 72));
const body = hexlify(buf.slice(72));
return { origin, sender, destination, recipient, body };
}
// TODO: move AbacusMessage into AbacusCore app
/**
@ -97,7 +72,7 @@ export function parseMessage(message: string): ParsedMessage {
*/
export class AbacusMessage {
readonly dispatch: AnnotatedDispatch;
readonly message: ParsedMessage;
readonly message: types.ParsedMessage;
readonly outbox: Outbox;
readonly inbox: Inbox;
@ -112,7 +87,7 @@ export class AbacusMessage {
) {
this.multiProvider = multiProvider;
this.core = core;
this.message = parseMessage(dispatch.event.args.message);
this.message = utils.parseMessage(dispatch.event.args.message);
this.dispatch = dispatch;
const messageNetworks = resolveNetworks(this.message);
@ -423,7 +398,10 @@ export class AbacusMessage {
* The messageHash committed to the tree in the Outbox contract.
*/
get leaf(): string {
return this.dispatch.event.args.messageHash;
return utils.messageHash(
this.dispatch.event.args.message,
this.dispatch.event.args.leafIndex.toNumber(),
);
}
/**

@ -23,7 +23,6 @@ export {
InboxContracts,
MessageStatus,
OutboxContracts,
parseMessage,
resolveDomain,
resolveId,
resolveNetworks,

@ -26,3 +26,11 @@ export enum MessageStatus {
NONE = 0,
PROCESSED,
}
export type ParsedMessage = {
origin: number;
sender: string;
destination: number;
recipient: string;
body: string;
};

@ -1,7 +1,8 @@
import { arrayify, hexlify } from '@ethersproject/bytes';
import { assert } from 'chai';
import { ethers } from 'ethers';
import { Address, Domain, HexString } from './types';
import { Address, Domain, HexString, ParsedMessage } from './types';
/*
* Gets the byte length of a hex string
@ -65,6 +66,22 @@ export const formatMessage = (
);
};
/**
* Parse a serialized Abacus message from raw bytes.
*
* @param message
* @returns
*/
export function parseMessage(message: string): ParsedMessage {
const buf = Buffer.from(arrayify(message));
const origin = buf.readUInt32BE(0);
const sender = hexlify(buf.slice(4, 36));
const destination = buf.readUInt32BE(36);
const recipient = hexlify(buf.slice(40, 72));
const body = hexlify(buf.slice(72));
return { origin, sender, destination, recipient, body };
}
export function messageHash(message: HexString, leafIndex: number): string {
return ethers.utils.solidityKeccak256(
['bytes', 'uint256'],

Loading…
Cancel
Save