Skip to content
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

Save external offchain transactions in optimist #641

Merged
merged 2 commits into from
May 6, 2022
Merged
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ cd node_modules/*
**/migrations/*
**/doc/*
cli/build/*
wallet/cli/*
test/adversary/nightfall-adversary/*
/**/*.d.ts
9 changes: 9 additions & 0 deletions common-files/utils/crypto/multihash.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint import/no-extraneous-dependencies: "off" */

import crypto from 'crypto';

let h = '875966a4d290bae914acd733315d1a1cbea3fb2b9fde133a0c6fffa7f726cbe3';
for (let i = 0; i < 1024; i++) {
h = crypto.createHash('sha256').update(h, 'hex').digest('hex');
}
console.log(h);
1 change: 0 additions & 1 deletion nightfall-deployer/migrations/2_deploy_upgradeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module.exports = async function (deployer) {
await challengers.setBootChallenger(bootChallenger);
const restrictions = await Shield.deployed();
// restrict transfer amounts
console.log('**TEST**', process.env.ETH_NETWORK, RESTRICTIONS.tokens, RESTRICTIONS);
for (let token of RESTRICTIONS.tokens[process.env.ETH_NETWORK]) {
console.log(`Max deposit restriction for ${token.name}: ${token.amount}`);
await restrictions.setRestriction(token.address, token.amount);
Expand Down
21 changes: 21 additions & 0 deletions nightfall-optimist/src/event-handlers/block-proposed.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
stampNullifiers,
getLatestTree,
saveTree,
getTransactionByTransactionHash,
} from '../services/database.mjs';
import { getProposeBlockCalldata } from '../services/process-calldata.mjs';
import transactionSubmittedEventHandler from './transaction-submitted.mjs';

const { ZERO, HASH_TYPE, TIMBER_HEIGHT } = config;

Expand Down Expand Up @@ -51,6 +53,25 @@ async function blockProposedEventHandler(data) {
// when a challenge is raised because the is correct block data, then the corresponding block deleted event will
// update this collection
await saveBlock({ blockNumber: currentBlockCount, transactionHashL1, ...block });

// It's possible that some of these transactions are new to us. That's because they were
// submitted by someone directly to another proposer and so there was never a TransactionSubmitted
// event associated with them. Either that, or we lost our database and had to resync from the chain.
// In which case this handler is being called be the resync code. either way, we need to add the transaction.
// let's use transactionSubmittedEventHandler to do this because it will perform all the duties associated
// with saving a transaction.
await Promise.all(
transactions.map(async tx => {
if (!(await getTransactionByTransactionHash(tx.transactionHash))) {
logger.debug(
`Processing external offchain transaction with L2 hash ${tx.transactionHash}`,
);
return transactionSubmittedEventHandler({ offchain: true, ...tx }); // must be offchain or we'll have seen them
}
return true;
}),
);

// Update the nullifiers we have stored, with the blockhash. These will
// be deleted if the block check fails and we get a rollback. We do this
// before running the block check because we want to delete the nullifiers
Expand Down
6 changes: 3 additions & 3 deletions nightfall-optimist/src/services/state-sync.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ const syncState = async (
case 'Rollback':
await rollbackEventHandler(pastEvent);
break;
case 'TransactionSubmitted':
await transactionSubmittedEventHandler(pastEvent);
break;
case 'BlockProposed':
await blockProposedEventHandler(pastEvent);
break;
case 'CommittedToChallenge':
await committedToChallengeEventHandler(pastEvent);
break;
case 'TransactionSubmitted':
await transactionSubmittedEventHandler(pastEvent);
break;
default:
break;
}
Expand Down