Author

Topic: Block number from getwork (Read 1598 times)

lfm
full member
Activity: 196
Merit: 104
March 03, 2011, 12:22:18 PM
#5
I'm looking for a way to verify if the current getwork I'm on is from the current, or last block. Would I be able to do that by looking at "prev_block", and checking against a stored array of the "prev_block" from the previous two blocks?

Like, I have an array with the two last known prev_block values in it. If the prev_block value from the getwork matches the newest stored prev_block value, I know it's from the current block. If it matches the oldest prev_block value, it's from the block prior to the current. Correct?


You would need to get the hash of the current "top" block and compare it to prev-hash in the getwork block.
administrator
Activity: 5222
Merit: 13032
March 02, 2011, 12:23:29 AM
#4
I'm looking for a way to verify if the current getwork I'm on is from the current, or last block. Would I be able to do that by looking at "prev_block", and checking against a stored array of the "prev_block" from the previous two blocks?

Like, I have an array with the two last known prev_block values in it. If the prev_block value from the getwork matches the newest stored prev_block value, I know it's from the current block. If it matches the oldest prev_block value, it's from the block prior to the current. Correct?

That won't work unless your getwork is putting you back to a block you've already seen, which it shouldn't do. The problem is getting the hash for the most recent block, which you have never seen before.

If you only need to get this data once in a while, you could use this:
http://blockexplorer.com/q/latesthash
Otherwise, you could patch your Bitcoin to support jgarzik's getblockbycount and then combine getblockbycount with getblockcount to get the hash of the latest block. If you have access to Bitcoin's debug.log, you can search it to find the latest block hash.
sr. member
Activity: 258
Merit: 250
March 01, 2011, 11:59:27 PM
#3
I'm looking for a way to verify if the current getwork I'm on is from the current, or last block. Would I be able to do that by looking at "prev_block", and checking against a stored array of the "prev_block" from the previous two blocks?

Like, I have an array with the two last known prev_block values in it. If the prev_block value from the getwork matches the newest stored prev_block value, I know it's from the current block. If it matches the oldest prev_block value, it's from the block prior to the current. Correct?
legendary
Activity: 1596
Merit: 1100
March 01, 2011, 11:31:54 PM
#2
How would one go about getting the current block number, in a readable format (i.e. the height of the block) from a getwork?

Current block chain height is not stored in the getwork data.

getwork data returns a block header, which includes things like previous-block-hash (forms the block chain).  See this example of a block:  http://blockexplorer.com/rawblock/000000000000aaa7a48683e8a184ebd4de700d3c7f29524d95a417b086793ac6
sr. member
Activity: 258
Merit: 250
March 01, 2011, 11:19:56 PM
#1
How would one go about getting the current block number, in a readable format (i.e. the height of the block) from a getwork?

How could/would this be done in python?
Jump to: