Skip to content

Commit

Permalink
block: replace cmp with their gt/lt equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Oct 29, 2020
1 parent 6d69a53 commit 34fa3ea
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class BlockHeader {
let a = blockTs.sub(parentTs).idivn(9).ineg().iaddn(uncleAddend)
const cutoff = new BN(-99)
// MAX(cutoff, a)
if (cutoff.cmp(a) === 1) {
if (cutoff.gt(a)) {
a = cutoff
}
dif = parentDif.add(offset.mul(a))
Expand Down Expand Up @@ -309,15 +309,13 @@ export class BlockHeader {
let a = blockTs.sub(parentTs).idivn(10).ineg().iaddn(1)
const cutoff = new BN(-99)
// MAX(cutoff, a)
if (cutoff.cmp(a) === 1) {
if (cutoff.gt(a)) {
a = cutoff
}
dif = parentDif.add(offset.mul(a))
} else {
// pre-homestead
if (
parentTs.addn(common.paramByHardfork('pow', 'durationLimit', hardfork)).cmp(blockTs) === 1
) {
if (parentTs.addn(common.paramByHardfork('pow', 'durationLimit', hardfork)).gt(blockTs)) {
dif = offset.add(parentDif)
} else {
dif = parentDif.sub(offset)
Expand All @@ -329,7 +327,7 @@ export class BlockHeader {
dif.iadd(new BN(2).pow(exp))
}

if (dif.cmp(minimumDifficulty) === -1) {
if (dif.lt(minimumDifficulty)) {
dif = minimumDifficulty
}

Expand Down Expand Up @@ -419,7 +417,7 @@ export class BlockHeader {

if (height) {
const dif = height.sub(header.number)
if (!(dif.cmpn(8) === -1 && dif.cmpn(1) === 1)) {
if (!(dif.ltn(8) && dif.gtn(1))) {
throw new Error('uncle block has a parent that is too old or too young')
}
}
Expand Down

0 comments on commit 34fa3ea

Please sign in to comment.