Skip to content

Commit

Permalink
Added parameter to set the block gas limit (#1245)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl authored and celo-ci-bot-user committed Nov 9, 2019
1 parent 2788391 commit 471735d
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 101 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ jobs:
cd packages/celotool
./ci_test_transfers.sh checkout master
end-to-end-geth-exit-test:
end-to-end-geth-blockchain-parameters-test:
<<: *e2e-defaults
steps:
- attach_workspace:
Expand All @@ -542,7 +542,7 @@ jobs:
command: |
set -e
cd packages/celotool
./ci_test_exit.sh checkout master
./ci_test_blockchain_parameters.sh checkout master
end-to-end-geth-governance-test:
<<: *e2e-defaults
Expand Down Expand Up @@ -748,7 +748,7 @@ workflows:
requires:
- lint-checks
- contractkit-test
- end-to-end-geth-exit-test:
- end-to-end-geth-blockchain-parameters-test:
requires:
- lint-checks
- contractkit-test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ if [ "${1}" == "checkout" ]; then
# Test master by default.
BRANCH_TO_TEST=${2:-"master"}
echo "Checking out geth at branch ${BRANCH_TO_TEST}..."
../../node_modules/.bin/mocha -r ts-node/register src/e2e-tests/exit_test.ts --branch ${BRANCH_TO_TEST}
../../node_modules/.bin/mocha -r ts-node/register src/e2e-tests/blockchain_parameters_tests.ts --branch ${BRANCH_TO_TEST}
elif [ "${1}" == "local" ]; then
export GETH_DIR="${2}"
echo "Testing using local geth dir ${GETH_DIR}..."
../../node_modules/.bin/mocha -r ts-node/register src/e2e-tests/exit_test.ts --localgeth ${GETH_DIR}
../../node_modules/.bin/mocha -r ts-node/register src/e2e-tests/blockchain_parameters_tests.ts --localgeth ${GETH_DIR}
fi
73 changes: 73 additions & 0 deletions packages/celotool/src/e2e-tests/blockchain_parameters_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// tslint:disable-next-line: no-reference (Required to make this work w/ ts-node)
/// <reference path="../../../contractkit/types/web3.d.ts" />

import { ContractKit, newKit } from '@celo/contractkit'
import { BlockchainParametersWrapper } from '@celo/contractkit/lib/wrappers/BlockchainParameters'
import { assert } from 'chai'
import { getHooks, GethTestConfig, sleep } from './utils'

describe('Blockchain parameters tests', function(this: any) {
this.timeout(0)

let kit: ContractKit
let parameters: BlockchainParametersWrapper

const gethConfig: GethTestConfig = {
migrateTo: 17,
instances: [
{ name: 'validator', validating: true, syncmode: 'full', port: 30303, rpcport: 8545 },
],
}
const hooks = getHooks(gethConfig)
before(hooks.before)
after(hooks.after)

const validatorAddress: string = '0x47e172f6cfb6c7d01c1574fa3e2be7cc73269d95'

const restartGeth = async () => {
// Restart the validator node
await hooks.restart()

// TODO(mcortesi): magic sleep. without it unlockAccount sometimes fails
await sleep(2)
kit = newKit('http://localhost:8545')
await kit.web3.eth.personal.unlockAccount(validatorAddress, '', 1000)
parameters = await kit.contracts.getBlockchainParameters()
}

const setMinimumClientVersion = async (major: number, minor: number, patch: number) => {
await parameters.setMinimumClientVersion(major, minor, patch).send({ from: validatorAddress })
}

describe('when running a node', () => {
before(async () => {
await restartGeth()
})
it('block limit should have been set using governance', async () => {
this.timeout(0)
const current = await kit.web3.eth.getBlockNumber()
const block = await kit.web3.eth.getBlock(current)
assert.equal(block.gasLimit, 20000000)
})
it('changing the block gas limit', async () => {
this.timeout(0)
await parameters.setBlockGasLimit(23000000).send({ from: validatorAddress })
await sleep(5)
const current = await kit.web3.eth.getBlockNumber()
const block = await kit.web3.eth.getBlock(current)
assert.equal(block.gasLimit, 23000000)
})
it('should exit when minimum version is updated', async () => {
this.timeout(0)
await setMinimumClientVersion(1, 8, 99)
await sleep(120)
try {
// It should have exited by now, call RPC to trigger error
await kit.web3.eth.getBlockNumber()
} catch (_) {
return
}
throw new Error('expected failure')
})
})
})
83 changes: 0 additions & 83 deletions packages/celotool/src/e2e-tests/exit_test.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/contractkit/src/wrappers/BlockchainParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ export class BlockchainParametersWrapper extends BaseWrapper<BlockchainParameter
this.kit,
this.contract.methods.setIntrinsicGasForAlternativeGasCurrency
)
/**
* Setting the block gas limit.
*/
setBlockGasLimit = proxySend(this.kit, this.contract.methods.setBlockGasLimit)
/**
* Set minimum client version.
*/
setMinimumClientVersion = proxySend(this.kit, this.contract.methods.setMinimumClientVersion)
}
33 changes: 27 additions & 6 deletions packages/protocol/contracts/governance/BlockchainParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ contract BlockchainParameters is Ownable, Initializable {
}

ClientVersion private minimumClientVersion;

uint256 public blockGasLimit;
uint256 public intrinsicGasForAlternativeGasCurrency;

event MinimumClientVersionSet(uint256 major, uint256 minor, uint256 patch);
event IntrinsicGasForAlternativeGasCurrencySet(uint256 gas);
event BlockGasLimitSet(uint256 limit);

/**
* @notice Initializes critical variables.
Expand All @@ -28,13 +29,19 @@ contract BlockchainParameters is Ownable, Initializable {
* minor version.
* @param patch Minimum client version that can be used in the chain,
* patch level.
* @param _gasForNonGoldCurrencies Intrinsic gas for non-gold gas currencies.
* @param gasLimit Block gas limit.
*/
function initialize(uint256 major, uint256 minor, uint256 patch, uint256 _gasForNonGoldCurrencies)
external
initializer
{
function initialize(
uint256 major,
uint256 minor,
uint256 patch,
uint256 _gasForNonGoldCurrencies,
uint256 gasLimit
) external initializer {
_transferOwnership(msg.sender);
setMinimumClientVersion(major, minor, patch);
setBlockGasLimit(gasLimit);
setIntrinsicGasForAlternativeGasCurrency(_gasForNonGoldCurrencies);
}

Expand All @@ -53,12 +60,26 @@ contract BlockchainParameters is Ownable, Initializable {
emit MinimumClientVersionSet(major, minor, patch);
}

/**
* @notice Sets the block gas limit.
* @param gasLimit New block gas limit.
*/
function setBlockGasLimit(uint256 gasLimit) public onlyOwner {
blockGasLimit = gasLimit;
emit BlockGasLimitSet(gasLimit);
}

/**
* @notice Sets the intrinsic gas for non-gold gas currencies.
* @param gas Intrinsic gas for non-gold gas currencies.
*/
function setIntrinsicGasForAlternativeGasCurrency(uint256 gas) public onlyOwner {
intrinsicGasForAlternativeGasCurrency = gas;
emit IntrinsicGasForAlternativeGasCurrencySet(gas);
}

/** @notice Query minimum client version.
/**
* @notice Query minimum client version.
* @return Returns major, minor, and patch version numbers.
*/
function getMinimumClientVersion()
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/lib/registry-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export const hasEntryInRegistry: string[] = [
CeloContractName.Election,
CeloContractName.Escrow,
CeloContractName.Exchange,
CeloContractName.GoldToken,
CeloContractName.GasCurrencyWhitelist,
CeloContractName.GasPriceMinimum,
CeloContractName.SortedOracles,
CeloContractName.StableToken,
CeloContractName.GoldToken,
CeloContractName.Random,
CeloContractName.Reserve,
CeloContractName.SortedOracles,
CeloContractName.StableToken,
]
1 change: 1 addition & 0 deletions packages/protocol/migrations/17_blockchainparams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const initializeArgs = async (_: string): Promise<any[]> => {
version.minor,
version.patch,
config.blockchainParameters.gasForNonGoldCurrencies,
config.blockchainParameters.blockGasLimit,
]
}

Expand Down
1 change: 1 addition & 0 deletions packages/protocol/migrationsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const DefaultConfig = {
minor: 8,
patch: 23,
},
blockGasLimit: 20000000,
},
election: {
minElectableValidators: '22',
Expand Down
Loading

0 comments on commit 471735d

Please sign in to comment.