Skip to content

Commit

Permalink
Add randSeed. Make txs with random work
Browse files Browse the repository at this point in the history
  • Loading branch information
1IxI1 committed Jul 18, 2024
1 parent f459b7e commit 718f7fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/runner/runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Converter', () => {
},
false
);
expect(res).toBe(36109845);
expect(res.mcSeqno).toBe(36109845);
});
});

Expand All @@ -109,6 +109,9 @@ describe('Runner', () => {
'https://ton.cx/tx/46843694000021:nwjPEIK88JGyPRLFVzNYHKkBb62OyVSgZKuU6J0mLC0=:EQA--JhKKuYfb-WAw7vDWEfD4fg2WOt9AuLH6xHPvF0RTUNA',
];

// it('should emulate with libs', async () => {
// });

it('should emulate first tx', async () => {
await waitForRateLimit();
const res = await getEmulationWithStack(first, false);
Expand Down Expand Up @@ -138,7 +141,7 @@ describe('Runner', () => {
for (let tx of txsWithRandom) {
await waitForRateLimit();
const res = await getEmulationWithStack(tx, false);
expect(res.stateUpdateHashOk).toBe(false);
expect(res.stateUpdateHashOk).toBe(true);
if (res.computeInfo !== 'skipped')
expect(res.computeInfo.success).toBe(true);
}
Expand Down
6 changes: 3 additions & 3 deletions src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export async function getEmulationWithStack(
const tx = (await clientV4.getAccountTransactions(address, lt, hash))[0];
console.log(tx.tx.now, 'tx time');
await waitForRateLimit();
const mcSeqno = await mcSeqnoByShard(tx.block, testnet);
const { mcSeqno, randSeed } = await mcSeqnoByShard(tx.block, testnet);
await waitForRateLimit();
const fullBlock = await clientV4.getBlock(mcSeqno);
const mcBlockSeqno = fullBlock.shards[0].seqno;
Expand Down Expand Up @@ -248,7 +248,7 @@ export async function getEmulationWithStack(
message: beginCell().store(storeMessage(_msg)).endCell(),
now: _tx.now,
lt: _tx.lt,
randomSeed: Buffer.alloc(32),
randomSeed: randSeed,
ignoreChksig: false,
debugEnabled: true,
});
Expand Down Expand Up @@ -372,7 +372,7 @@ export async function getEmulationWithStack(
}

if (line.startsWith('stack:')) {
console.log('Parsing stack for', instruction, line);
// console.log('Parsing stack for', instruction, line);
const stack = parseStack(line);
// got stack. now link it with the instruction
if (instruction) {
Expand Down
11 changes: 9 additions & 2 deletions src/runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export async function mcSeqnoByShard(
fileHash: string;
},
testnet: boolean
): Promise<number> {
): Promise<{
mcSeqno: number;
randSeed: Buffer;
}> {
try {
const shardInt = BigInt(shard.shard);
const shardUint =
Expand All @@ -64,7 +67,11 @@ export async function mcSeqnoByShard(
block.root_hash
);
}
return block.masterchain_block_ref.seqno;
console.log(block);
return {
mcSeqno: block.masterchain_block_ref.seqno,
randSeed: Buffer.from(block.rand_seed, 'base64'),
};
} catch (error) {
console.error('Error fetching mc_seqno:', error);
throw error;
Expand Down

0 comments on commit 718f7fa

Please sign in to comment.