Skip to content

Commit

Permalink
fix(service): check message status, catch contract errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kfastov committed Oct 2, 2024
1 parent 679e3db commit 57926f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/services/rootPropagator/modules/L1/L1MessageListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ export async function listenForL1Messages() {
}

async function processEvent(event) {
const [_from, to, fee, value, nonce, calldata, messageHash] = event.args;
const [from, to, fee, value, nonce, calldata, messageHash] = event.args;
logger.info('Processing MessageSent Event', {
nonce,
messageHash,
});

try {
await saveMessage({
messageSender: from,
destination: to,
messageHash: messageHash,
nonce: nonce.toString(),
Expand Down
33 changes: 20 additions & 13 deletions src/services/rootPropagator/modules/L2/L2MessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,21 @@ export async function claimL2Messages() {

for (const message of unclaimedMessages) {
try {
console.log('Claiming message', { messageHash: message.messageHash });
console.log('message contents', {
messageSender: config.lineaStateBridgeAddress,
destination: message.destination,
fee: message.fee,
value: message.value,
messageNonce: message.nonce,
calldata: message.calldata,
messageHash: message.messageHash
});
logger.info('Claiming message', { messageHash: message.messageHash });

const status = await l2Contract.getMessageStatus(message.messageHash);

if (status === 'CLAIMED') {
logger.info('Message already claimed', { messageHash: message.messageHash });
await updateMessageStatus(message.messageHash, 'claimed');
continue;
} else if (status !== 'CLAIMABLE') {
logger.error('Message status is not claimable', { messageHash: message.messageHash, status });
continue;
}

const tx = await l2Contract.claim({
messageSender: config.lineaStateBridgeAddress,
messageSender: message.messageSender,
destination: message.destination,
fee: message.fee,
value: message.value,
Expand All @@ -126,9 +129,13 @@ export async function claimL2Messages() {
logger.info('Message claimed successfully', { messageHash: message.messageHash });
await updateMessageStatus(message.messageHash, 'claimed');
} catch (error) {
logger.error('Error claimed message', { messageHash: message.messageHash, error: error.message });
if (error.message.includes('0x6650c4d1')) {
logger.warn('Message claim failed due to CannotOverwriteRoot error', { messageHash: message.messageHash });
await updateMessageStatus(message.messageHash, 'failed');
} else {
logger.error('Error claiming message', { messageHash: message.messageHash, error: error.message });
}
}
// break // process only one message for now
}

// Clean up claimed messages
Expand Down

0 comments on commit 57926f6

Please sign in to comment.