Skip to content

Commit

Permalink
Fix: Requested changes related to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ajimeno04 committed Jun 27, 2024
1 parent 8bff4cf commit b94db83
Showing 1 changed file with 55 additions and 62 deletions.
117 changes: 55 additions & 62 deletions src/collector/layer-zero/layer-zero.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class LayerZeroWorker {
bridgeAddress: this.config.bridgeAddress,
receiverAddress: this.config.receiverAddress,
},
`Monitoring contracts: bridgeAddress and receiverAddress.`,
`LayerZero collector worker started.`,
);
let fromBlock = null;
while (fromBlock == null) {
Expand All @@ -183,7 +183,6 @@ class LayerZeroWorker {
await wait(this.config.processingInterval);
}
const stopBlock = this.config.stoppingBlock ?? Infinity;
this.logger.info(`Stop block set to ${stopBlock}`);
while (true) {
try {
let toBlock = this.currentStatus?.blockNumber;
Expand All @@ -204,7 +203,7 @@ class LayerZeroWorker {
await this.queryAndProcessEvents(fromBlock, toBlock);
this.logger.info(
{ fromBlock, toBlock },
`Scanning LayerZero Endpoint messages: fromBlock to toBlock.`,
`Scanning LayerZero events.`,
);
if (toBlock >= stopBlock) {
this.logger.info(
Expand Down Expand Up @@ -241,7 +240,7 @@ class LayerZeroWorker {
} catch (error) {
this.logger.error(
{ log, error },
`Failed to process event on layer-zero collector worker: log and error details.`,
`Failed to process event on layer-zero collector worker.`,
);
}
}
Expand Down Expand Up @@ -295,7 +294,7 @@ class LayerZeroWorker {
if (parsedLog == null) {
this.logger.error(
{ topics: log.topics, data: log.data },
`Failed to parse event: log topics and data details.`,
`Failed to parse LayerZero event.`,
);
return;
}
Expand All @@ -312,7 +311,7 @@ class LayerZeroWorker {
default:
this.logger.warn(
{ name: parsedLog.name, topic: parsedLog.topic },
`Event with unknown name/topic received: parsedLog details.`,
`Event with unknown name/topic received.`,
);
}
}
Expand Down Expand Up @@ -341,7 +340,7 @@ class LayerZeroWorker {

this.logger.debug(
{ transactionHash: log.transactionHash, packet, options, sendLibrary },
'PacketSent event found: log details.',
'PacketSent event found.',
);

if (srcEidMapped === undefined || dstEidMapped === undefined) {
Expand Down Expand Up @@ -369,61 +368,52 @@ class LayerZeroWorker {
{ sender: packet.sender, message: packet.message },
'Processing packet from specific sender: sender and message details.',
);
const transactionBlockNumber =
await this.resolver.getTransactionBlockNumber(log.blockNumber);
await this.store.setAmb(
{
messageIdentifier: decodedMessage.messageIdentifier,
amb: 'layer-zero',
sourceChain: srcEidMapped.toString(),
destinationChain: dstEidMapped.toString(),
sourceEscrow: packet.sender,
payload: decodedMessage.message,
recoveryContext: '0x',
blockNumber: log.blockNumber,
transactionBlockNumber,
blockHash: log.blockHash,
transactionHash: log.transactionHash,
},
log.transactionHash,
);

try {
const transactionBlockNumber =
await this.resolver.getTransactionBlockNumber(log.blockNumber);
await this.store.setAmb(
{
messageIdentifier: decodedMessage.messageIdentifier,
amb: 'layer-zero',
sourceChain: srcEidMapped.toString(),
destinationChain: dstEidMapped.toString(),
sourceEscrow: packet.sender,
payload: decodedMessage.message,
recoveryContext: '0x',
blockNumber: log.blockNumber,
transactionBlockNumber,
blockHash: log.blockHash,
transactionHash: log.transactionHash,
},
log.transactionHash,
);
const payloadHash = this.calculatePayloadHash(
packet.guid,
packet.message,
);

this.logger.info(
{ transactionHash: log.transactionHash },
'Primary AMB message created using setAmb: transactionHash details.',
);
await this.store.setPayload('layer-zero', 'ambMessage', payloadHash, {
messageIdentifier: decodedMessage.messageIdentifier,
destinationChain: dstEidMapped,
payload: encodedPayload,
});

const payloadHash = this.calculatePayloadHash(
packet.guid,
packet.message,
);
await this.store.setPayload('layer-zero', 'ambMessage', payloadHash, {
this.logger.info(
{
messageIdentifier: decodedMessage.messageIdentifier,
destinationChain: dstEidMapped,
payload: encodedPayload,
});

this.logger.info(
{ payloadHash, transactionHash: log.transactionHash },
'Secondary AMB message created with payload hash as key using setPayloadLayerZeroAmb: payloadHash and transactionHash details.',
);
} catch (innerError) {
this.logger.error(
{ innerError, log },
'Failed to process specific sender packet: innerError and log details.',
);
throw innerError;
}
transactionHash: log.transactionHash,
payloadHash
},
'Collected message.',
);
} else {
this.logger.debug(
{ sender: packet.sender },
'Skipping packet: sender is not a GARP contract.',
);
}
} catch (error) {
this.logger.error({ error, log }, 'Failed to handle PacketSent event: error and log details.');
this.logger.error({ error, log }, 'Failed to handle PacketSent event.');
}
}

Expand All @@ -442,15 +432,22 @@ class LayerZeroWorker {
const srcEidMapped = this.layerZeroChainIdMap[decodedHeader.srcEid];
const dstEidMapped = this.layerZeroChainIdMap[decodedHeader.dstEid];
if (srcEidMapped === undefined || dstEidMapped === undefined) {
throw new Error('Failed to map srcEidMapped or dstEidMapped.');
this.logger.error(
{
srcEid: decodedHeader.srcEid,
dstEid: decodedHeader.dstEid
},
'Failed to map srcEidMapped or dstEidMapped.',
);
return;
}
if (
decodedHeader.sender.toLowerCase() ===
this.incentivesAddresses[srcEidMapped]
) {
this.logger.info(
{ dvn, decodedHeader, confirmations, proofHash },
'PayloadVerified event decoded: dvn, decodedHeader, confirmations, and proofHash details.',
'PayloadVerified event decoded.',
);
const payloadData = await this.store.getPayload('layer-zero', 'ambMessage', proofHash);
if (!payloadData) {
Expand All @@ -460,10 +457,6 @@ class LayerZeroWorker {
);
return;
}
this.logger.info(
{ payloadData },
'Data fetched from database using payloadHash: payloadData details.',
);
try {
const config = await getConfigData(
this.receiveULN302,
Expand All @@ -476,7 +469,6 @@ class LayerZeroWorker {
keccak256(header),
proofHash,
);
this.logger.info({ dvn, isVerifiable }, 'Verification result checked: dvn and isVerifiable details.');
if (isVerifiable) {
const ambPayload: AmbPayload = {
messageIdentifier: '0x' + payloadData.messageIdentifier,
Expand All @@ -485,16 +477,18 @@ class LayerZeroWorker {
message: payloadData.payload,
messageCtx: '0x',
};
this.logger.info({ proofHash }, `LayerZero proof found: proofHash details.`);
this.logger.info({ proofHash }, `LayerZero proof found.`);
await this.store.submitProof(
this.layerZeroChainIdMap[decodedHeader.dstEid]!,
ambPayload,
);
} else {
this.logger.debug('Payload could not be verified');
}
} catch (error) {
this.logger.error(
{ error: tryErrorToString(error) },
'Error during configuration verification: error details.',
'Error during payload verification.',
);
}
}
Expand Down Expand Up @@ -585,8 +579,7 @@ async function checkIfVerifiable(
);
return isVerifiable;
} catch (error) {
console.error('Error verifying the configuration: ', error);
throw new Error('Error verifying the configuration: error details.');
throw new Error('Error verifying the payload.');
}
}

Expand Down

0 comments on commit b94db83

Please sign in to comment.