Skip to content

Commit

Permalink
Merge pull request #913 from ainblockchain/release/v1.0.3
Browse files Browse the repository at this point in the history
Release/v1.0.3
  • Loading branch information
platfowner authored Jan 14, 2022
2 parents caa6967 + cc82cb0 commit e367d19
Show file tree
Hide file tree
Showing 28 changed files with 696 additions and 274 deletions.
1 change: 1 addition & 0 deletions blockchain-configs/afan-shard/node_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"MAX_NUM_INBOUND_CONNECTION": 3,
"MAX_NUM_SNAPSHOTS": 10,
"ON_MEMORY_CHAIN_LENGTH": 10,
"P2P_GENESIS_BLOCK_HASH_MISMATCH_SLEEP_MS": 10000,
"P2P_HEARTBEAT_INTERVAL_MS": 15000,
"P2P_MESSAGE_TIMEOUT_MS": 600000,
"P2P_PORT": 5000,
Expand Down
1 change: 1 addition & 0 deletions blockchain-configs/base/node_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"MAX_NUM_INBOUND_CONNECTION": 6,
"MAX_NUM_SNAPSHOTS": 10,
"ON_MEMORY_CHAIN_LENGTH": 10,
"P2P_GENESIS_BLOCK_HASH_MISMATCH_SLEEP_MS": 10000,
"P2P_HEARTBEAT_INTERVAL_MS": 15000,
"P2P_MESSAGE_TIMEOUT_MS": 600000,
"P2P_PORT": 5000,
Expand Down
4 changes: 4 additions & 0 deletions blockchain-configs/base/timer_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
"staking_balance_total_sum": {
"enabled_block": 2,
"has_bandage": true
},
"update_max_state_tree_size_per_byte2": {
"enabled_block": 3,
"has_bandage": true
}
}
1 change: 1 addition & 0 deletions blockchain-configs/he-shard/node_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"MAX_NUM_INBOUND_CONNECTION": 6,
"MAX_NUM_SNAPSHOTS": 10,
"ON_MEMORY_CHAIN_LENGTH": 10,
"P2P_GENESIS_BLOCK_HASH_MISMATCH_SLEEP_MS": 10000,
"P2P_HEARTBEAT_INTERVAL_MS": 15000,
"P2P_MESSAGE_TIMEOUT_MS": 600000,
"P2P_PORT": 5000,
Expand Down
1 change: 1 addition & 0 deletions blockchain-configs/mainnet-prod/node_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"MAX_NUM_INBOUND_CONNECTION": 6,
"MAX_NUM_SNAPSHOTS": 10,
"ON_MEMORY_CHAIN_LENGTH": 10,
"P2P_GENESIS_BLOCK_HASH_MISMATCH_SLEEP_MS": 10000,
"P2P_HEARTBEAT_INTERVAL_MS": 15000,
"P2P_MESSAGE_TIMEOUT_MS": 600000,
"P2P_PORT": 5000,
Expand Down
4 changes: 4 additions & 0 deletions blockchain-configs/mainnet-prod/timer_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
"staking_balance_total_sum": {
"enabled_block": 44600,
"has_bandage": true
},
"update_max_state_tree_size_per_byte2": {
"enabled_block": 58300,
"has_bandage": true
}
}
1 change: 1 addition & 0 deletions blockchain-configs/sim-shard/node_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"MAX_NUM_INBOUND_CONNECTION": 6,
"MAX_NUM_SNAPSHOTS": 10,
"ON_MEMORY_CHAIN_LENGTH": 10,
"P2P_GENESIS_BLOCK_HASH_MISMATCH_SLEEP_MS": 10000,
"P2P_HEARTBEAT_INTERVAL_MS": 15000,
"P2P_MESSAGE_TIMEOUT_MS": 600000,
"P2P_PORT": 5000,
Expand Down
1 change: 1 addition & 0 deletions blockchain-configs/testnet-dev/node_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"MAX_NUM_INBOUND_CONNECTION": 6,
"MAX_NUM_SNAPSHOTS": 10,
"ON_MEMORY_CHAIN_LENGTH": 10,
"P2P_GENESIS_BLOCK_HASH_MISMATCH_SLEEP_MS": 10000,
"P2P_HEARTBEAT_INTERVAL_MS": 15000,
"P2P_MESSAGE_TIMEOUT_MS": 600000,
"P2P_PORT": 5000,
Expand Down
1 change: 1 addition & 0 deletions blockchain-configs/testnet-prod/node_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"MAX_NUM_INBOUND_CONNECTION": 6,
"MAX_NUM_SNAPSHOTS": 10,
"ON_MEMORY_CHAIN_LENGTH": 10,
"P2P_GENESIS_BLOCK_HASH_MISMATCH_SLEEP_MS": 10000,
"P2P_HEARTBEAT_INTERVAL_MS": 15000,
"P2P_MESSAGE_TIMEOUT_MS": 600000,
"P2P_PORT": 5000,
Expand Down
4 changes: 4 additions & 0 deletions blockchain-configs/testnet-prod/timer_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
"staking_balance_total_sum": {
"enabled_block": 42300,
"has_bandage": true
},
"update_max_state_tree_size_per_byte2": {
"enabled_block": 56300,
"has_bandage": true
}
}
1 change: 1 addition & 0 deletions blockchain-configs/testnet-sandbox/node_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"MAX_NUM_INBOUND_CONNECTION": 6,
"MAX_NUM_SNAPSHOTS": 10,
"ON_MEMORY_CHAIN_LENGTH": 10,
"P2P_GENESIS_BLOCK_HASH_MISMATCH_SLEEP_MS": 10000,
"P2P_HEARTBEAT_INTERVAL_MS": 15000,
"P2P_MESSAGE_TIMEOUT_MS": 600000,
"P2P_PORT": 5000,
Expand Down
1 change: 1 addition & 0 deletions blockchain-configs/testnet-staging/node_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"MAX_NUM_INBOUND_CONNECTION": 6,
"MAX_NUM_SNAPSHOTS": 10,
"ON_MEMORY_CHAIN_LENGTH": 10,
"P2P_GENESIS_BLOCK_HASH_MISMATCH_SLEEP_MS": 10000,
"P2P_HEARTBEAT_INTERVAL_MS": 15000,
"P2P_MESSAGE_TIMEOUT_MS": 600000,
"P2P_PORT": 5000,
Expand Down
8 changes: 8 additions & 0 deletions blockchain/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ class Block {
return JSON.stringify(this, null, 2);
}

// TODO(platfowner): Add a richer validation function (ref: Transaction.isInStandardFormat()).
static hasRequiredFields(block) {
return CommonUtil.isDict(block) && block.number !== undefined &&
block.timestamp !== undefined && block.hash !== undefined &&
block.last_hash !== undefined && block.last_votes !== undefined &&
block.transactions !== undefined && block.state_proof_hash !== undefined;
}

static sanitizeTransactions(transactions) {
const sanitized = [];
transactions.forEach((tx) => {
Expand Down
3 changes: 3 additions & 0 deletions client/protocol_versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,8 @@
},
"1.0.2": {
"min": "1.0.0"
},
"1.0.3": {
"min": "1.0.0"
}
}
2 changes: 2 additions & 0 deletions common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ if (!semver.valid(BlockchainConsts.CONSENSUS_PROTOCOL_VERSION)) {

// ** Timer flags **
const TimerFlags = getBlockchainConfig('timer_flags.json');

function isEnabledTimerFlag(flagName, blockNumber) {
return CommonUtil.hasTimerFlagEnabled(TimerFlags, flagName, blockNumber);
}

function isTimerFlagEnabledAt(flagName, blockNumber) {
return CommonUtil.getTimerFlagEnabledBlock(TimerFlags, flagName) === blockNumber;
}

const TimerFlagEnabledBandageMap = CommonUtil.createTimerFlagEnabledBandageMap(TimerFlags);

// ** Blockchain params **
Expand Down
11 changes: 6 additions & 5 deletions common/result-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@ const TxResultCode = {
// Gas
GAS_EXCEED_STATE_BUDGET_LIMIT_FOR_ALL_SERVICES: 10901,
GAS_EXCEED_STATE_BUDGET_LIMIT_FOR_ALL_APPS: 10902,
GAS_EXCEED_STATE_TREE_SIZE_LIMIT_FOR_ALL_SERVICES: 10903,
GAS_EXCEED_STATE_TREE_SIZE_LIMIT_FOR_ALL_APPS: 10904,
GAS_EXCEED_STATE_TREE_SIZE_LIMIT_FOR_ALL_SERVICES: 10903, // Not used since #917
GAS_EXCEED_STATE_TREE_SIZE_LIMIT_FOR_ALL_APPS: 10904, // Not used since #917
GAS_EXCEED_STATE_BUDGET_LIMIT_FOR_FREE_TIER: 10905,
GAS_EXCEED_STATE_TREE_SIZE_LIMIT_FOR_FREE_TIER: 10906,
GAS_EXCEED_STATE_TREE_SIZE_LIMIT_FOR_FREE_TIER: 10906, // Not used since #917
GAS_EXCEED_STATE_BUDGET_LIMIT_FOR_APP: 10907,
GAS_EXCEED_STATE_TREE_SIZE_LIMIT_FOR_APP: 10908,
GAS_EXCEED_STATE_TREE_SIZE_LIMIT_FOR_APP: 10908, // Not used since #917
// Fee
FEE_BALANCE_TOO_LOW: 11001,
FEE_FAILED_TO_COLLECT_GAS_FEE: 11002,
// Tree
TREE_OUT_OF_TREE_HEIGHT_LIMIT: 11101,
TREE_OUT_OF_TREE_SIZE_LIMIT: 11102,
TREE_OUT_OF_TREE_SIZE_LIMIT: 11102, // Not used since #917
TREE_OUT_OF_TREE_BYTES_LIMIT: 11103, // Used since #917
// Eval rule
EVAL_RULE_NON_EMPTY_SUBTREE_RULES: 12101,
EVAL_RULE_INTERNAL_ERROR: 12102,
Expand Down
42 changes: 28 additions & 14 deletions consensus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,20 +749,27 @@ class Consensus {
}
}

static validateStateProofHash(expectedStateProofHash, number, db, node, takeSnapshot) {
static validateStateProofHash(expectedStateProofHash, block, db, node, takeSnapshot) {
const LOG_HEADER = 'validateStateProofHash';
if (NodeConfigs.LIGHTWEIGHT) return;

const blockNumber = block.number;
const stateProofHash = db.getProofHash('/');
if (stateProofHash !== expectedStateProofHash) {
if (takeSnapshot) {
// NOTE(platfowner): Write the current snapshot for debugging.
const snapshot = node.buildBlockchainSnapshot(number, db.stateRoot);
const snapshot = node.buildBlockchainSnapshot(blockNumber, block, db.stateRoot);
const snapshotChunkSize = node.getBlockchainParam('resource/snapshot_chunk_size');
// NOTE(liayoo): This write is not awaited.
FileUtil.writeSnapshotFile(node.snapshotDir, number, snapshot, snapshotChunkSize, true);
FileUtil.writeSnapshotFile(node.snapshotDir, blockNumber, snapshot, snapshotChunkSize, true);
}
const message =
`Block of number ${blockNumber} has a mismatched state proof hash: ${stateProofHash} / ${expectedStateProofHash}`
+ `\n${new Error().stack}.`;
logger.error(`[${LOG_HEADER}] ${message}`);
throw new ConsensusError({
code: ConsensusErrorCode.INVALID_STATE_PROOF_HASH,
message: `State proof hashes don't match (${number}): ${stateProofHash} / ${expectedStateProofHash}`,
message: message,
level: 'error'
});
}
Expand Down Expand Up @@ -846,7 +853,7 @@ class Consensus {
Consensus.validateAndExecuteTransactions(
transactions, receipts, number, timestamp, gas_amount_total, gas_cost_total, db, node);
db.applyBandagesForBlockNumber(number);
Consensus.validateStateProofHash(state_proof_hash, number, db, node, takeSnapshot);
Consensus.validateStateProofHash(state_proof_hash, block, db, node, takeSnapshot);
Consensus.executeProposalTx(proposalTx, number, timestamp, db, node);
Consensus.addBlockToBlockPool(block, proposalTx, db, node.bp);
} catch (e) {
Expand Down Expand Up @@ -892,10 +899,10 @@ class Consensus {
const voteTimestamp = ConsensusUtil.getTimestampFromVoteTx(voteTx);
const blockInfo = this.node.bp.hashToBlockInfo.get(blockHash) ||
this.node.bp.hashToInvalidBlockInfo.get(blockHash);
let block;
let block = null;
if (blockInfo && blockInfo.block) {
block = blockInfo.block;
} else if (blockHash === this.node.bc.lastBlock().hash) {
} else if (this.node.bc.lastBlock() && blockHash === this.node.bc.lastBlock().hash) {
block = this.node.bc.lastBlock();
}
if (!block) {
Expand Down Expand Up @@ -1048,20 +1055,26 @@ class Consensus {
this.handleConsensusMessage(consensusMsg);
}

catchUp(blockList) {
catchUp(catchUpList) {
const LOG_HEADER = 'catchUp';
if (!blockList || !blockList.length) return;

if (!catchUpList || !catchUpList.length) return;
let lastVerifiedBlockInfo;
const lastNotarizedBlock = this.getLastNotarizedBlock();
logger.info(`[${LOG_HEADER}] Current lastNotarizedBlock: ` +
`${lastNotarizedBlock.number} / ${lastNotarizedBlock.epoch}`);
for (const blockInfo of blockList) {
// NOTE(platfowner): lastNotarizedBlock = null in cold start.
if (lastNotarizedBlock) {
logger.info(`[${LOG_HEADER}] Current lastNotarizedBlock: ` +
`${lastNotarizedBlock.number} / ${lastNotarizedBlock.epoch}`);
} else {
logger.info(`[${LOG_HEADER}] Current lastNotarizedBlock: ${lastNotarizedBlock}`);
}
for (const blockInfo of catchUpList) {
logger.debug(`[${LOG_HEADER}] Adding notarized chain's block: ` +
`${JSON.stringify(blockInfo, null, 2)}`);
if (!blockInfo.block || !blockInfo.proposal) {
break;
}
if (blockInfo.block.number < lastNotarizedBlock.number) {
if (lastNotarizedBlock && blockInfo.block.number < lastNotarizedBlock.number) {
continue;
}
try {
Expand Down Expand Up @@ -1125,7 +1138,8 @@ class Consensus {

getSnapDb(latestBlock) {
const LOG_HEADER = 'getSnapDb';
const lastFinalizedHash = this.node.bc.lastBlock().hash;
const lastBlock = this.node.bc.lastBlock();
const lastFinalizedHash = lastBlock ? lastBlock.hash : null;
const chain = [];
let currBlock = latestBlock;
let blockHash = currBlock.hash;
Expand Down
9 changes: 9 additions & 0 deletions db/bandage-files/update_max_state_tree_size_per_byte2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
data: [
{
path: ['values', 'blockchain_params', 'resource', 'max_state_tree_size_per_byte'],
value: 0.00625,
prevValue: 0.1
}
]
};
Loading

0 comments on commit e367d19

Please sign in to comment.