-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make MinGasPrice consensus param (#163)
* make MinGasPrice consensus param * add minGasPrice to relay * don't check minGas against bridgeState, check against state
- Loading branch information
1 parent
a5545ad
commit 24887bf
Showing
18 changed files
with
200 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) 2018-present, Leap DAO (leapdao.org) | ||
* | ||
* This source code is licensed under the Mozilla Public License Version 2.0 | ||
* found in the LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const { Type } = require('leap-core'); | ||
const { BigInt, equal } = require('jsbi-utils'); | ||
|
||
module.exports = (state, tx, bridgeState) => { | ||
if (tx.type !== Type.MIN_GAS_PRICE) { | ||
throw new Error('minGasPrice tx expected'); | ||
} | ||
|
||
if (state.gas.minPriceIndex + 1 !== bridgeState.minGasPrices.length - 1) { | ||
throw new Error('Unknown minGasPrice change'); | ||
} | ||
|
||
if ( | ||
!equal( | ||
BigInt(bridgeState.minGasPrices[state.gas.minPriceIndex + 1]), | ||
BigInt(tx.options.minGasPrice) | ||
) | ||
) { | ||
throw new Error('Wrong minGasPrice'); | ||
} | ||
|
||
state.gas.minPriceIndex += 1; | ||
state.gas.minPrice = BigInt(tx.options.minGasPrice).toString(); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { Tx } = require('leap-core'); | ||
|
||
const checkMinGasPrice = require('./checkMinGasPrice'); | ||
|
||
const getInitialState = () => ({ | ||
gas: { | ||
minPrice: 0, | ||
minPriceIndex: -1, | ||
}, | ||
}); | ||
|
||
describe('checkMinGasPrice', () => { | ||
test('wrong type', () => { | ||
const tx = Tx.transfer([], []); | ||
expect(() => checkMinGasPrice({}, tx)).toThrow('minGasPrice tx expected'); | ||
}); | ||
|
||
test('successful tx', () => { | ||
const state = getInitialState(); | ||
const minGasTx = Tx.minGasPrice('40000000000000'); | ||
|
||
checkMinGasPrice(state, minGasTx, { | ||
minGasPrices: ['40000000000000'], | ||
}); | ||
|
||
expect(state.gas.minPrice).toBe('40000000000000'); | ||
}); | ||
|
||
test('tx without corresponding event', () => { | ||
const state = getInitialState(); | ||
const minGasTx = Tx.minGasPrice('40000000000000'); | ||
|
||
expect(() => { | ||
checkMinGasPrice(state, minGasTx, { | ||
minGasPrices: [], | ||
}); | ||
}).toThrow('Unknown minGasPrice change'); | ||
}); | ||
|
||
test('epoch length mismatch', () => { | ||
const state = getInitialState(); | ||
const minGasTx = Tx.minGasPrice('40000000000000'); | ||
|
||
expect(() => { | ||
checkMinGasPrice(state, minGasTx, { | ||
minGasPrices: ['55555555555555'], | ||
}); | ||
}).toThrow('Wrong minGasPrice'); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.