Merge branch 'master' of github.com:status-im/nim-eth

This commit is contained in:
Ștefan Talpalaru 2019-07-10 15:35:19 +02:00
commit 93637fa060
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
3 changed files with 23 additions and 12 deletions

View File

@ -180,6 +180,12 @@ when BlockNumber is int64:
template toBlockNumber*(n: SomeInteger): BlockNumber = template toBlockNumber*(n: SomeInteger): BlockNumber =
int64(n) int64(n)
template toBlockNumber*(n: UInt256): BlockNumber =
n.toInt
template toInt*(n: BlockNumber): int =
int(n)
else: else:
template vmWordToBlockNumber*(word: VMWord): BlockNumber = template vmWordToBlockNumber*(word: VMWord): BlockNumber =
word word
@ -190,6 +196,12 @@ else:
template toBlockNumber*(n: SomeInteger): BlockNumber = template toBlockNumber*(n: SomeInteger): BlockNumber =
u256(n) u256(n)
template toBlockNumber*(n: UInt256): BlockNumber =
n
template u256*(n: BlockNumber): UInt256 =
n
proc toBlockNonce*(n: uint64): BlockNonce = proc toBlockNonce*(n: uint64): BlockNonce =
bigEndian64(addr result[0], unsafeAddr n) bigEndian64(addr result[0], unsafeAddr n)
@ -303,7 +315,7 @@ proc read*(rlp: var Rlp, T: typedesc[HashOrNum]): T =
if rlp.blobLen == 32: if rlp.blobLen == 32:
result = HashOrNum(isHash: true, hash: rlp.read(Hash256)) result = HashOrNum(isHash: true, hash: rlp.read(Hash256))
else: else:
result = HashOrNum(isHash: false, number: rlp.read(UInt256)) result = HashOrNum(isHash: false, number: rlp.read(BlockNumber))
proc append*(rlpWriter: var RlpWriter, t: Time) {.inline.} = proc append*(rlpWriter: var RlpWriter, t: Time) {.inline.} =
rlpWriter.append(t.toUnix()) rlpWriter.append(t.toUnix())

View File

@ -40,7 +40,7 @@ proc hash*(p: Peer): Hash {.inline.} = hash(cast[pointer](p))
proc endIndex(b: WantedBlocks): BlockNumber = proc endIndex(b: WantedBlocks): BlockNumber =
result = b.startIndex result = b.startIndex
result += (b.numBlocks - 1).u256 result += (b.numBlocks - 1).toBlockNumber
proc availableWorkItem(ctx: SyncContext): int = proc availableWorkItem(ctx: SyncContext): int =
var maxPendingBlock = ctx.finalizedBlock var maxPendingBlock = ctx.finalizedBlock

View File

@ -10,8 +10,7 @@ proc getBlockHeaders*(db: AbstractChainDB,
var foundBlock: BlockHeader var foundBlock: BlockHeader
if db.getBlockHeader(req.startBlock, foundBlock): if db.getBlockHeader(req.startBlock, foundBlock):
result.add foundBlock result.add foundBlock
# Quick sanity check for lower bounds, code should be safe though without.
if not req.reverse or (foundBlock.blockNumber >= (req.skip + 1).toBlockNumber):
while uint64(result.len) < req.maxResults: while uint64(result.len) < req.maxResults:
if not req.reverse: if not req.reverse:
if not db.getSuccessorHeader(foundBlock, foundBlock, req.skip): if not db.getSuccessorHeader(foundBlock, foundBlock, req.skip):