MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / async_routine

Method async_routine

test/functional/interface_ipc_mining.py:135–159  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

133 block_hash_size = 32
134
135 async def async_routine():
136 ctx, mining = await make_mining_ctx(self)
137 blockref = await mining.getTip(ctx)
138 current_block_height = self.nodes[0].getchaintips()[0]["height"]
139 assert_equal(blockref.result.height, current_block_height)
140
141 self.log.debug("Mine a block")
142 newblockref = (await wait_and_do(
143 mining.waitTipChanged(ctx, blockref.result.hash, self.default_ipc_timeout),
144 lambda: self.generate(self.nodes[0], 1))).result
145 assert_equal(len(newblockref.hash), block_hash_size)
146 assert_equal(newblockref.height, current_block_height + 1)
147 self.log.debug("Wait for timeout")
148 oldblockref = (await mining.waitTipChanged(ctx, newblockref.hash, self.default_ipc_timeout)).result
149 assert_equal(len(newblockref.hash), block_hash_size)
150 assert_equal(oldblockref.hash, newblockref.hash)
151 assert_equal(oldblockref.height, newblockref.height)
152
153 self.log.debug("interrupt() should abort waitTipChanged()")
154 async def wait_for_tip():
155 long_timeout = max(self.default_ipc_timeout, 60000.0) # at least 1 minute
156 result = (await mining.waitTipChanged(ctx, newblockref.hash, long_timeout)).result
157 # Unlike a timeout, interrupt() returns an empty BlockRef.
158 assert_equal(len(result.hash), 0)
159 await wait_and_do(wait_for_tip(), mining.interrupt())
160
161 asyncio.run(capnp.run(async_routine()))
162

Callers

nothing calls this directly

Calls 15

build_candidate_blockMethod · 0.95
assert_submit_blockMethod · 0.95
build_coinbase_testMethod · 0.95
make_mining_ctxFunction · 0.90
assert_equalFunction · 0.90
wait_and_doFunction · 0.90
from_hexFunction · 0.90
CBlockHeaderClass · 0.90
P2PInterfaceClass · 0.90
msg_headersClass · 0.90
destroyingFunction · 0.90

Tested by

no test coverage detected