Ignore messages during message processing in TipProver (#281)

pull/285/head
Nam Chu Hoai 3 years ago committed by GitHub
parent fae4152221
commit a9b509e973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      rust/agents/relayer/src/checkpoint_relayer.rs
  2. 18
      solidity/core/contracts/test/bad-recipient/RandomBadRecipient.sol
  3. 41
      solidity/core/test/badrecipient.test.ts
  4. 4
      typescript/deploy/hardhat.config.ts

@ -4,7 +4,7 @@ use abacus_base::{CachingInbox, CheckpointSyncer, CheckpointSyncers};
use abacus_core::{db::AbacusDB, AbacusCommon, CommittedMessage, Inbox};
use color_eyre::Result;
use tokio::{task::JoinHandle, time::sleep};
use tracing::{debug, info_span, instrument::Instrumented, Instrument};
use tracing::{debug, error, info, info_span, instrument::Instrumented, Instrument};
use crate::tip_prover::{MessageBatch, TipProver};
@ -94,9 +94,15 @@ impl CheckpointRelayer {
// TODO: sign in parallel
for message in &batch.messages {
if let Some(proof) = self.db.proof_by_leaf_index(message.leaf_index)? {
self.inbox
.prove_and_process(&message.message, &proof)
.await?;
// Ignore errors and expect the lagged message processor to retry
match self.inbox.prove_and_process(&message.message, &proof).await {
Ok(outcome) => {
info!(txHash=?outcome.txid, leaf_index=message.leaf_index, "TipProver processed message")
}
Err(error) => {
error!(error=?error, leaf_index=message.leaf_index, "TipProver encountered error while processing message, ignoring")
}
}
}
}

@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
import {IMessageRecipient} from "../../../interfaces/IMessageRecipient.sol";
contract BadRandomRecipient is IMessageRecipient {
event Handled(bytes32 blockHash);
function handle(
uint32,
bytes32,
bytes memory
) external override {
bool isBlockHashEven = uint256(blockhash(block.number - 1)) % 2 == 0;
require(isBlockHashEven, "block hash is odd");
emit Handled(blockhash(block.number - 1));
}
}

@ -0,0 +1,41 @@
import { ethers } from 'hardhat';
import { BadRandomRecipient__factory } from '../types';
import { utils } from '@abacus-network/utils';
import { expect } from 'chai';
describe('BadRecipient', () => {
describe('RandomBadRecipient', () => {
it('randomly handles a message', async () => {
const [signer] = await ethers.getSigners();
const signerAddress = await signer.getAddress();
const recipientFactory = new BadRandomRecipient__factory(signer);
const recipient = await recipientFactory.deploy();
// Didn't know how else to test the randomness
let successes = 0;
let failures = 0;
for (let i = 0; i < 10; i++) {
try {
// "Inject randomness"
await signer.sendTransaction({
from: signerAddress,
to: signerAddress,
value: 1,
});
await recipient.handle(
0,
utils.addressToBytes32(recipient.address),
'0x1234',
);
successes += 1;
} catch (error) {
failures += 1;
}
}
expect(successes).to.be.greaterThan(1);
expect(failures).to.be.greaterThan(1);
});
});
});

@ -2,7 +2,7 @@ import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-etherscan';
import { task } from 'hardhat/config';
import { types, utils } from '@abacus-network/utils';
import { TestRecipient__factory } from '@abacus-network/core';
import { BadRandomRecipient__factory } from '@abacus-network/core';
import { sleep } from './src/utils/utils';
import {
@ -79,7 +79,7 @@ task('kathy', 'Dispatches random abacus messages')
// Deploy a recipient
const [signer] = await hre.ethers.getSigners();
const recipientF = new TestRecipient__factory(signer);
const recipientF = new BadRandomRecipient__factory(signer);
const recipient = await recipientF.deploy();
await recipient.deployTransaction.wait();

Loading…
Cancel
Save