Skip to content

Commit

Permalink
Merge pull request #50 from hive-engine/qa
Browse files Browse the repository at this point in the history
Merge for release 1.10.0
  • Loading branch information
bt-cryptomancer committed Jul 12, 2023
2 parents a15ca74 + 8946095 commit c842167
Show file tree
Hide file tree
Showing 17 changed files with 525 additions and 144 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ACTIVE_SIGNING_KEY=5K...
ACCOUNT=acc...
NODE_IP=...
# Only use one of the following:
# NODE_IP=...
NODE_DOMAIN=...
# If your public ports are different from your node config.js ports (requires NAT/port forwarding)
#RPCNODEPORT=15000
#P2PPORT=15001
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contracts/revert/*.js
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: '${{ matrix.os }}'
strategy:
matrix:
os: [ubuntu-20.04]
os: [ubuntu-22.04]
node-version: [16.x, 18.x]
mongodb-version: ['4.4', '5.0', '6.0']

Expand Down
1 change: 1 addition & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"maxOffset" : -1,
"maxBatchLength" : 1,
"logRequests" : false,
"allowArbitraryProject" : false,
"disabledMethods" : {
"blockchain" : ["getBlockRangeInfo"],
"contracts" : []
Expand Down
10 changes: 5 additions & 5 deletions contracts/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ async function tokenMaintenance() {

const nextClaimDecayTimestamp = lastClaimDecayTimestamp + rewardIntervalDurationMillis;
if (nextClaimDecayTimestamp >= nextRewardTimestamp) {
let rewardPerInterval = config.rewardPerInterval;
let { rewardPerInterval } = config;
if (config.rewardReductionIntervalSeconds && config.rewardReductionPercentage) {
const rewardReductionIntervalMillis = config.rewardReductionIntervalSeconds * 1000;
const nextRewardReductionTimestamp = rewardPool.lastRewardReductionTimestamp + rewardReductionIntervalMillis;
Expand Down Expand Up @@ -565,7 +565,7 @@ actions.createRewardPool = async (payload) => {
appTaxConfig,
excludeTags,
rewardReductionIntervalSeconds,
rewardReductionPercentage
rewardReductionPercentage,
} = config;

if (!api.assert(postRewardCurve && postRewardCurve === 'power', 'postRewardCurve should be one of: [power]')) return;
Expand Down Expand Up @@ -604,7 +604,7 @@ actions.createRewardPool = async (payload) => {
if (!api.assert(!rewardReductionIntervalSeconds || (Number.isInteger(rewardReductionIntervalSeconds) && rewardReductionIntervalSeconds >= rewardIntervalSeconds), 'rewardReductionIntervalSeconds should be an integer greater or equal to rewardIntervalSeconds')) return;
const rewardReductionPercentageDecimal = api.BigNumber(rewardReductionPercentage);
if (!api.assert(!rewardReductionPercentage || (typeof rewardReductionPercentage === 'string' && rewardReductionPercentageDecimal.isFinite() && rewardReductionPercentageDecimal.gte('0') && rewardReductionPercentageDecimal.lte('100') && rewardReductionPercentageDecimal.dp() <= 1), 'rewardReductionPercentage should be between "0" and "100" with precision at most 1')) return;


// for now, restrict to 1 pool per symbol, and creator must be issuer.
// eslint-disable-next-line no-template-curly-in-string
Expand Down Expand Up @@ -644,7 +644,7 @@ actions.createRewardPool = async (payload) => {
appTaxConfig,
excludeTags,
rewardReductionIntervalSeconds,
rewardReductionPercentage
rewardReductionPercentage,
},
pendingClaims: '0',
active: true,
Expand Down Expand Up @@ -704,7 +704,7 @@ actions.updateRewardPool = async (payload) => {
appTaxConfig,
excludeTags,
rewardReductionIntervalSeconds,
rewardReductionPercentage
rewardReductionPercentage,
} = config;

const existingRewardPool = await api.db.findOne('rewardPools', { _id: rewardPoolId });
Expand Down
60 changes: 51 additions & 9 deletions contracts/witnesses.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,13 @@ actions.updateWitnessesApprovals = async (payload) => {

actions.register = async (payload) => {
const {
IP, RPCPort, P2PPort, signingKey, enabled, isSignedWithActiveKey,
domain, IP, RPCPort, P2PPort, signingKey, enabled, isSignedWithActiveKey,
} = payload;

if (api.assert(isSignedWithActiveKey === true, 'active key required')
&& api.assert(IP && typeof IP === 'string' && api.validator.isIP(IP), 'IP is invalid')
&& api.assert(domain || IP, 'neither domain nor ip provided')
&& api.assert(!(domain && IP), 'both domain and ip provided')
&& ((domain && api.assert(domain && typeof domain === 'string' && api.validator.isFQDN(domain), 'domain is invalid')) || (IP && api.assert(IP && typeof IP === 'string' && api.validator.isIP(IP), 'IP is invalid')))
&& api.assert(RPCPort && Number.isInteger(RPCPort) && RPCPort >= 0 && RPCPort <= 65535, 'RPCPort must be an integer between 0 and 65535')
&& api.assert(P2PPort && Number.isInteger(P2PPort) && P2PPort >= 0 && P2PPort <= 65535, 'P2PPort must be an integer between 0 and 65535')
&& api.assert(api.validator.isAlphanumeric(signingKey) && signingKey.length === 53, 'invalid signing key')
Expand All @@ -236,26 +238,49 @@ actions.register = async (payload) => {
let witness = await api.db.findOne('witnesses', { signingKey });

if (api.assert(witness === null || witness.account === api.sender, 'a witness is already using this signing key')) {
// check if there is already a witness with the same IP/Port
witness = await api.db.findOne('witnesses', { IP, P2PPort });

if (api.assert(witness === null || witness.account === api.sender, 'a witness is already using this IP/Port')) {
// check if there is already a witness with the same IP/Port or domain
if (IP){
witness = await api.db.findOne('witnesses', { IP, P2PPort });
} else {
witness = await api.db.findOne('witnesses', { domain, P2PPort });
}

if (api.assert(witness === null || witness.account === api.sender, `a witness is already using this ${IP ? 'IP' : 'domain'}/Port`)) {
witness = await api.db.findOne('witnesses', { account: api.sender });

// if the witness is already registered
if (witness) {
witness.IP = IP;
let useUnsets = false;
let unsets = {};
if (IP){
witness.IP = IP;
if (witness.domain){
delete witness['domain'];
unsets.domain = '';
useUnsets = true;
}
} else {
witness.domain = domain;
if (witness.IP){
delete witness['IP'];
unsets.IP = '';
useUnsets = true;
}
}
witness.RPCPort = RPCPort;
witness.P2PPort = P2PPort;
witness.signingKey = signingKey;
witness.enabled = enabled;
await api.db.update('witnesses', witness);
if (useUnsets){
await api.db.update('witnesses', witness, unsets);
} else {
await api.db.update('witnesses', witness);
}
} else {
witness = {
account: api.sender,
approvalWeight: { $numberDecimal: '0' },
signingKey,
IP,
RPCPort,
P2PPort,
enabled,
Expand All @@ -265,6 +290,11 @@ actions.register = async (payload) => {
lastRoundVerified: null,
lastBlockVerified: null,
};
if (IP){
witness.IP = IP;
} else {
witness.domain = domain;
}
await api.db.insert('witnesses', witness);
}
}
Expand Down Expand Up @@ -509,10 +539,16 @@ const changeCurrentWitness = async () => {
scheduledWitness.missedRounds += 1;
scheduledWitness.missedRoundsInARow += 1;

// Emit that witness missed round
api.emit('witnessMissedRound', { witness: scheduledWitness.account });

// disable the witness if missed maxRoundsMissedInARow
if (scheduledWitness.missedRoundsInARow >= maxRoundsMissedInARow) {
scheduledWitness.missedRoundsInARow = 0;
scheduledWitness.enabled = false;

// Emit that witness got disabled
api.emit('witnessDisabledForMissingTooManyRoundsInARow', { witness: scheduledWitness.account });
}

await api.db.update('witnesses', scheduledWitness);
Expand Down Expand Up @@ -564,10 +600,16 @@ const changeCurrentWitness = async () => {
scheduledWitness.missedRounds += 1;
scheduledWitness.missedRoundsInARow += 1;

// Emit that witness missed round
api.emit('witnessMissedRound', { witness: scheduledWitness.account });

// disable the witness if missed maxRoundsMissedInARow
if (scheduledWitness.missedRoundsInARow >= maxRoundsMissedInARow) {
scheduledWitness.missedRoundsInARow = 0;
scheduledWitness.enabled = false;

// Emit that witness got disabled
api.emit('witnessDisabledForMissingTooManyRoundsInARow', { witness: scheduledWitness.account });
}

await api.db.update('witnesses', scheduledWitness);
Expand Down
71 changes: 35 additions & 36 deletions find_divergent_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { node, headOnly } = program;

let id = 1;

async function getBlock(blockNumber, tries=1) {
async function getBlock(blockNumber, tries = 1) {
id += 1;
try {
return (await axios({
Expand All @@ -36,11 +36,10 @@ async function getBlock(blockNumber, tries=1) {
if (tries >= 3) {
console.error(error);
return null;
} else {
console.log(`Attempt #${tries} failed, retrying...`);
await new Promise((r) => setTimeout(() => r(), 500));
return await getBlock(blockNumber, tries + 1);
}
console.log(`Attempt #${tries} failed, retrying...`);
await new Promise(r => setTimeout(() => r(), 500));
return await getBlock(blockNumber, tries + 1);
}
}

Expand All @@ -55,7 +54,7 @@ const blockData = t => ({
});
function getCompareData(block) {
return block;
//return block.transactions.map(blockData).concat( block.virtualTransactions.map(blockData),);
// return block.transactions.map(blockData).concat( block.virtualTransactions.map(blockData),);
}
function getCompareString(block) {
return JSON.stringify(getCompareData(block));
Expand All @@ -64,33 +63,33 @@ function compareBlocks(block1, block2) {
return getCompareString(block1) === getCompareString(block2);
}
function printBlockDiff(block, mainBlock) {
// go through transactions, then virtual transactions, then overall hash
if (!block) {
console.log('This node missing block');
} else if (!mainBlock) {
console.log('Comparison node missing block');
} else {
for (let i = 0; i < block.transactions.length; i += 1) {
const txString = JSON.stringify(block.transactions[i]);
const mainTxString = JSON.stringify(mainBlock.transactions[i]);
if (txString === mainTxString) {
console.log(`Transaction ${i} matches`);
} else {
console.log(`Transaction ${i} mismatch: This: ${txString}, Main: ${mainTxString}`);
return;
}
}
for (let i = 0; i < block.virtualTransactions.length; i += 1) {
const txString = JSON.stringify(block.virtualTransactions[i]);
const mainTxString = JSON.stringify(mainBlock.virtualTransactions[i]);
if (txString === mainTxString) {
console.log(`Virtual Transaction ${i} matches`);
} else {
console.log(`Virtual Transaction ${i} mismatch: This: ${txString}, Main: ${mainTxString}`);
return;
}
}
// go through transactions, then virtual transactions, then overall hash
if (!block) {
console.log('This node missing block');
} else if (!mainBlock) {
console.log('Comparison node missing block');
} else {
for (let i = 0; i < block.transactions.length; i += 1) {
const txString = JSON.stringify(block.transactions[i]);
const mainTxString = JSON.stringify(mainBlock.transactions[i]);
if (txString === mainTxString) {
console.log(`Transaction ${i} matches`);
} else {
console.log(`Transaction ${i} mismatch: This: ${txString}, Main: ${mainTxString}`);
return;
}
}
for (let i = 0; i < block.virtualTransactions.length; i += 1) {
const txString = JSON.stringify(block.virtualTransactions[i]);
const mainTxString = JSON.stringify(mainBlock.virtualTransactions[i]);
if (txString === mainTxString) {
console.log(`Virtual Transaction ${i} matches`);
} else {
console.log(`Virtual Transaction ${i} mismatch: This: ${txString}, Main: ${mainTxString}`);
return;
}
}
}
}

async function findDivergentBlock() {
Expand Down Expand Up @@ -127,10 +126,10 @@ async function findDivergentBlock() {
} else {
let low = 0;
if (lightNode.enabled) {
const firstBlock = await chain.findOne({ blockNumber: { $gt: 0 } });
if (firstBlock) {
low = firstBlock.blockNumber;
}
const firstBlock = await chain.findOne({ blockNumber: { $gt: 0 } });
if (firstBlock) {
low = firstBlock.blockNumber;
}
}
let high = block._id;
const headBlock = high;
Expand Down
2 changes: 1 addition & 1 deletion libs/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class Block {

// add odd blocks, consensus appended double virtual transactions
if (this.refHiveBlockNumber === 59376574) {
this.virtualTransactions = this.virtualTransactions.concat(this.virtualTransactions);
this.virtualTransactions = this.virtualTransactions.concat(this.virtualTransactions);
}

if (this.transactions.length > 0 || this.virtualTransactions.length > 0) {
Expand Down

0 comments on commit c842167

Please sign in to comment.