Created
May 16, 2018 22:09
-
-
Save nodech/07ea88f285e6c7f2f0573b9a6e24c8f5 to your computer and use it in GitHub Desktop.
Mine maximum block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should mine a big block', async () => { | |
const OPRETURN = Script.fromNulldata(Buffer.alloc(70, 1)); | |
const start = chain.height - 2000; | |
const end = chain.height - 200; | |
const job = await cpu.createJob(); | |
const maxSigops = consensus.maxBlockSigops(consensus.MAX_FORK_BLOCK_SIZE); | |
const perTxSigops = Math.floor((maxSigops - 1000) / 1801) - 2; | |
const perTxSize = Math.floor(consensus.MAX_FORK_BLOCK_SIZE / 1801); | |
// fill max tx | |
// with 1801 transactions, | |
// limits sigops to maxSigops for a block | |
// and calculates expected tx size for each one | |
// that is filled with OP_RETURN | |
// consensus size: 117 bytes | |
for (let i = start; i <= end; i++) { | |
const block = await chain.getBlock(i); | |
const cb = block.txs[0]; // 117 bytes | |
const mtx = new MTX(); | |
mtx.addTX(cb, 0); // 51 bytes | |
const fillSize = perTxSize - (51 + 107 + (perTxSigops * 34)); | |
const opreturns = Math.floor(fillSize / 81); | |
for (let j = 0; j < perTxSigops; j++) | |
mtx.addOutput(wallet.getAddress(), 1); // 34 bytes | |
for (let j = 0; j < opreturns; j++) | |
mtx.addOutput({ script: OPRETURN }); | |
wallet.sign(mtx); // 107 bytes | |
job.pushTX(mtx.toTX()); | |
} | |
job.refresh(); | |
assert.strictEqual(await mineBlock(job), 'OK'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment