Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
Fix bugs related to minor changes to elastic document handling after …
Browse files Browse the repository at this point in the history
…quering db, unwrap _soruce[@raw] at highest posible point, right after db read
  • Loading branch information
guilledk committed Apr 9, 2024
1 parent 0d26bb5 commit 2f67cca
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/routes/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ export default async function (fastify: FastifyInstance, opts: TelosEvmConfig) {
}
}

function getVRS(receiptDoc): {v: string, r: string, s: string} {
let receipt = receiptDoc["@raw"];
function getVRS(receipt): {v: string, r: string, s: string} {
const v = removeLeftZeros(BigInt(receipt.v).toString(16), true);
const r = removeLeftZeros(receipt.r, true);
const s = removeLeftZeros(receipt.s, true);
Expand Down Expand Up @@ -441,9 +440,8 @@ export default async function (fastify: FastifyInstance, opts: TelosEvmConfig) {
let bloom = new Bloom();
const trxs = [];
//Logger.debug(`Reconstructing block from receipts: ${JSON.stringify(receipts)}`)
for (const receiptDoc of receipts) {
const {v, r, s} = getVRS(receiptDoc._source);
const receipt = receiptDoc._source['@raw'];
for (const receipt of receipts) {
const {v, r, s} = getVRS(receipt);

if (!blockHash) {
blockHash = addHexPrefix(receipt['block_hash']);
Expand Down Expand Up @@ -521,7 +519,7 @@ export default async function (fastify: FastifyInstance, opts: TelosEvmConfig) {
size: 2000,
query: { bool: { must: [{ term: termStruct }] } }
});
return results?.hits?.hits;
return results?.hits?.hits.map(h => h._source['@raw']);
}

async function getCurrentBlockNumber(indexed: boolean = false) {
Expand Down Expand Up @@ -1264,7 +1262,7 @@ export default async function (fastify: FastifyInstance, opts: TelosEvmConfig) {
block = await emptyBlockFromHash(_hash);

else {
const blockNum = receipts[0]['@raw'].block;
const blockNum = receipts[0].block;
const delta = await getDeltaDocFromNumber(blockNum);
block = reconstructBlockFromReceipts(delta, receipts, true, client);
}
Expand Down Expand Up @@ -1311,8 +1309,8 @@ export default async function (fastify: FastifyInstance, opts: TelosEvmConfig) {
block = await emptyBlockFromHash(_hash);

else {
const blockNum = receipts[0]['@raw'].block;
const delta = await getDeltaDocFromNumber(blockNum);
const blockNum = receipts[0].block;
const delta = await getDeltaDocFromNumber(blockNum - opts.blockNumberDelta);
block = reconstructBlockFromReceipts(delta, receipts, true, client);
}
return block;
Expand Down Expand Up @@ -1701,8 +1699,7 @@ export default async function (fastify: FastifyInstance, opts: TelosEvmConfig) {
throw new Error("trace_replayBlockTransactions only supports the \"trace\" type of trace (not vmTrace or stateDiff");

const blockNumber = parseInt(await toBlockNumber(block), 16);
const receiptHits = await getReceiptsByTerm("@raw.block", blockNumber);
const receipts = receiptHits.map(r => r._source["@raw"]);
const receipts = await getReceiptsByTerm("@raw.block", blockNumber);
const sortedReceipts = receipts.sort((a, b) => {
return a.trx_index - b.trx_index;
})
Expand All @@ -1719,8 +1716,7 @@ export default async function (fastify: FastifyInstance, opts: TelosEvmConfig) {

methods.set('trace_block', async ([block]) => {
const blockNumber = parseInt(await toBlockNumber(block), 16);
const receiptHits = await getReceiptsByTerm("@raw.block", blockNumber);
const receipts = receiptHits.map(r => r._source["@raw"]);
const receipts = await getReceiptsByTerm("@raw.block", blockNumber);
const sortedReceipts = receipts.sort((a, b) => {
return a.trx_index - b.trx_index;
})
Expand Down

0 comments on commit 2f67cca

Please sign in to comment.