From 72a4e8416e8f7b80a4d1049db4b5caf8afdaf88f Mon Sep 17 00:00:00 2001 From: cryptomancer <8011332+bt-cryptomancer@users.noreply.github.com> Date: Sun, 25 Feb 2024 10:42:18 +0900 Subject: [PATCH] Revert "Only reward witness who produced the round and Use Only Enabled Witnesses For Scheduling" --- contracts/witnesses.js | 101 +++++++--------- test/witnesses.js | 260 +++-------------------------------------- 2 files changed, 54 insertions(+), 307 deletions(-) diff --git a/contracts/witnesses.js b/contracts/witnesses.js index 44f36cd..d44f187 100644 --- a/contracts/witnesses.js +++ b/contracts/witnesses.js @@ -8,16 +8,14 @@ const NB_WITNESSES = NB_TOP_WITNESSES + NB_BACKUP_WITNESSES; const NB_WITNESSES_SIGNATURES_REQUIRED = 14; const MAX_ROUNDS_MISSED_IN_A_ROW = 3; // after that the witness is disabled const MAX_ROUND_PROPOSITION_WAITING_PERIOD = 40; // number of blocks -const NB_TOKENS_TO_REWARD_PER_BLOCK = '0.01902586'; // inflation.js tokens per block -const NB_TOKENS_NEEDED_BEFORE_REWARDING = '0.39954306'; // 21x to reward +const NB_TOKENS_TO_REWARD = '0.01902586'; // inflation.js tokens per block +const NB_TOKENS_NEEDED_BEFORE_REWARDING = '0.0951293'; // 5x to reward // eslint-disable-next-line max-len const WITNESS_APPROVE_EXPIRE_BLOCKS = 5184000; // Approximately half a year, 20 blocks a minute * 60 minutes an hour * 24 hours a day * 180 days const WITNESS_MAX_ACCOUNT_EXPIRE_PER_BLOCK = 10; // eslint-disable-next-line no-template-curly-in-string const UTILITY_TOKEN_SYMBOL = "'${CONSTANTS.UTILITY_TOKEN_SYMBOL}$'"; // eslint-disable-next-line no-template-curly-in-string -const UTILITY_TOKEN_PRECISION = '${CONSTANTS.UTILITY_TOKEN_PRECISION}$'; -// eslint-disable-next-line no-template-curly-in-string const GOVERNANCE_TOKEN_SYMBOL = "'${CONSTANTS.GOVERNANCE_TOKEN_SYMBOL}$'"; // eslint-disable-next-line no-template-curly-in-string const GOVERNANCE_TOKEN_PRECISION = '${CONSTANTS.GOVERNANCE_TOKEN_PRECISION}$'; @@ -35,8 +33,7 @@ actions.createSSC = async () => { await api.db.createTable('params'); const params = { - totalApprovalWeight: '0', // deprecated in favor of totalEnabledApprovalWeight, but do not remove immediately in case we need to go back to using this if any major issue is found - totalEnabledApprovalWeight: '0', + totalApprovalWeight: '0', numberOfApprovedWitnesses: 0, lastVerifiedBlockNumber: 0, round: 0, @@ -57,22 +54,19 @@ actions.createSSC = async () => { } else { const params = await api.db.findOne('params', {}); // This should be removed after being deployed - if (!params.totalEnabledApprovalWeight) { - let totalEnabledApprovalWeight = '0'; + if (!params.witnessApproveExpireBlocks) { let offset = 0; - let wits; + let accounts; do { - wits = await api.db.find('witnesses', {}, 1000, offset, [{ index: '_id', descending: false }]); - for (let i = 0; i < wits.length; i += 1) { - const wit = wits[i]; - if (wit.enabled) { - totalEnabledApprovalWeight = api.BigNumber(totalEnabledApprovalWeight) - .plus(wit.approvalWeight).toFixed(GOVERNANCE_TOKEN_PRECISION); - } + accounts = await api.db.find('accounts', {}, 1000, offset, [{ index: '_id', descending: false }]); + for (let i = 0; i < accounts.length; i += 1) { + const account = accounts[i]; + account.lastApproveBlock = api.blockNumber; + await api.db.update('accounts', account); } offset += 1000; - } while (wits.length === 1000); - params.totalEnabledApprovalWeight = totalEnabledApprovalWeight; + } while (accounts.length === 1000); + params.witnessApproveExpireBlocks = WITNESS_APPROVE_EXPIRE_BLOCKS; await api.db.update('params', params); } // End block to remove @@ -172,12 +166,6 @@ const updateWitnessRank = async (witness, approvalWeight) => { .plus(approvalWeight) .toFixed(GOVERNANCE_TOKEN_PRECISION); - // if witness is enabled, add update totalEnabledApprovalWeight - if (witnessRec.enabled) { - params.totalEnabledApprovalWeight = api.BigNumber(params.totalEnabledApprovalWeight) - .plus(approvalWeight).toFixed(GOVERNANCE_TOKEN_PRECISION); - } - // update numberOfApprovedWitnesses if (api.BigNumber(oldApprovalWeight).eq(0) && api.BigNumber(witnessRec.approvalWeight.$numberDecimal).gt(0)) { @@ -251,31 +239,30 @@ actions.register = async (payload) => { 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 or domain - if (IP) { + 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) { - const enabledChanged = witness.enabled !== enabled; let useUnsets = false; - const unsets = {}; - if (IP) { + let unsets = {}; + if (IP){ witness.IP = IP; - if (witness.domain) { - delete witness.domain; + if (witness.domain){ + delete witness['domain']; unsets.domain = ''; useUnsets = true; } } else { witness.domain = domain; - if (witness.IP) { - delete witness.IP; + if (witness.IP){ + delete witness['IP']; unsets.IP = ''; useUnsets = true; } @@ -284,21 +271,11 @@ actions.register = async (payload) => { witness.P2PPort = P2PPort; witness.signingKey = signingKey; witness.enabled = enabled; - if (useUnsets) { + if (useUnsets){ await api.db.update('witnesses', witness, unsets); } else { await api.db.update('witnesses', witness); } - const params = await api.db.findOne('params', {}); - // update totalEnabledApprovalWeight if the witness' enable status changed - if (enabledChanged && witness.enabled) { - params.totalEnabledApprovalWeight = api.BigNumber(params.totalEnabledApprovalWeight) - .plus(witness.approvalWeight).toFixed(GOVERNANCE_TOKEN_PRECISION); - } else if (enabledChanged && !witness.enabled) { - params.totalEnabledApprovalWeight = api.BigNumber(params.totalEnabledApprovalWeight) - .minus(witness.approvalWeight).toFixed(GOVERNANCE_TOKEN_PRECISION); - } - await api.db.update('params', params); } else { witness = { account: api.sender, @@ -313,13 +290,12 @@ actions.register = async (payload) => { lastRoundVerified: null, lastBlockVerified: null, }; - if (IP) { + if (IP){ witness.IP = IP; } else { witness.domain = domain; } await api.db.insert('witnesses', witness); - // no need to update totalEnabledApprovalWeight here as the approvalWeight is always 0 } } } @@ -492,7 +468,7 @@ const changeCurrentWitness = async () => { const params = await api.db.findOne('params', {}); const { currentWitness, - totalEnabledApprovalWeight, + totalApprovalWeight, lastWitnesses, lastBlockRound, round, @@ -503,7 +479,7 @@ const changeCurrentWitness = async () => { let witnessFound = false; // get a deterministic random weight const random = api.random(); - const randomWeight = api.BigNumber(totalEnabledApprovalWeight) + const randomWeight = api.BigNumber(totalApprovalWeight) .times(random) .toFixed(GOVERNANCE_TOKEN_PRECISION, 1); @@ -518,7 +494,6 @@ const changeCurrentWitness = async () => { $numberDecimal: '0', }, }, - enabled: true, }, 100, // limit offset, // offset @@ -651,7 +626,7 @@ const manageWitnessesSchedule = async () => { const params = await api.db.findOne('params', {}); const { numberOfApprovedWitnesses, - totalEnabledApprovalWeight, + totalApprovalWeight, lastVerifiedBlockNumber, blockNumberWitnessChange, lastBlockRound, @@ -706,7 +681,6 @@ const manageWitnessesSchedule = async () => { $numberDecimal: '0', }, }, - enabled: true, }, 100, // limit offset, // offset @@ -724,7 +698,7 @@ const manageWitnessesSchedule = async () => { && randomWeight === null) { randomWeight = api.BigNumber(accWeight) .plus(GOVERNANCE_TOKEN_MIN_VALUE) - .plus(api.BigNumber(totalEnabledApprovalWeight) + .plus(api.BigNumber(totalApprovalWeight) .minus(accWeight) .times(random) .toFixed(GOVERNANCE_TOKEN_PRECISION, 1)) @@ -870,7 +844,6 @@ actions.proposeRound = async (payload) => { lastBlockRound, currentWitness, } = params; - const schedules = await api.db.find('schedules', { round }, 1000, 0, [{ index: '_id', descending: false }]); const numberOfWitnessSlots = schedules.length; @@ -940,19 +913,25 @@ actions.proposeRound = async (payload) => { await api.verifyBlock(verifiedBlockInformation[index]); } - // remove the schedules - for (let index = 0; index < schedules.length; index += 1) { - const schedule = schedules[index]; - await api.db.remove('schedules', schedule); - } - // reward the current witness + // get contract balance const contractBalance = await api.db.findOneInTable('tokens', 'contractsBalances', { account: 'witnesses', symbol: UTILITY_TOKEN_SYMBOL }); + let rewardWitnesses = false; + if (contractBalance && api.BigNumber(contractBalance.balance).gte(NB_TOKENS_NEEDED_BEFORE_REWARDING)) { - const rewardAmount = api.BigNumber(NB_TOKENS_TO_REWARD_PER_BLOCK).multipliedBy(numberOfWitnessSlots).toFixed(UTILITY_TOKEN_PRECISION); + rewardWitnesses = true; + } + + // remove the schedules + for (let index = 0; index < schedules.length; index += 1) { + const schedule = schedules[index]; + // reward the witness that help verifying this round + if (rewardWitnesses === true) { await api.executeSmartContract('tokens', 'stakeFromContract', { - to: currentWitness, symbol: UTILITY_TOKEN_SYMBOL, quantity: rewardAmount, + to: schedule.witness, symbol: UTILITY_TOKEN_SYMBOL, quantity: NB_TOKENS_TO_REWARD, }); + } + await api.db.remove('schedules', schedule); } params.currentWitness = null; diff --git a/test/witnesses.js b/test/witnesses.js index 264761d..d3249eb 100644 --- a/test/witnesses.js +++ b/test/witnesses.js @@ -390,7 +390,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 2); assert.equal(params[0].totalApprovalWeight, "200.00000"); - assert.equal(params[0].totalEnabledApprovalWeight, "100.00000"); transactions = []; transactions.push(new Transaction(32713426, fixture.getNextTxId(), 'satoshi', 'witnesses', 'register', `{ "IP": "123.234.123.245", "RPCPort": 5000, "P2PPort": 6000, "signingKey": "STM7sw22HqsXbz7D2CmJfmMwt9rimtk518dRzsR1f8Cgw52dQR1pJ", "enabled": true, "isSignedWithActiveKey": true }`)); @@ -479,7 +478,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 3); assert.equal(params[0].totalApprovalWeight, "300.00002"); - assert.equal(params[0].totalEnabledApprovalWeight, "200.00002"); resolve(); }) @@ -595,7 +593,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 3); assert.equal(params[0].totalApprovalWeight, "300.00001"); - assert.equal(params[0].totalEnabledApprovalWeight, "200.00001") transactions = []; transactions.push(new Transaction(37899123, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'witnesses', 'disapprove', `{ "witness": "satoshi", "isSignedWithActiveKey": true }`)); @@ -668,7 +665,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 2); assert.equal(params[0].totalApprovalWeight, "200.00001"); - assert.equal(params[0].totalEnabledApprovalWeight, "100.00001") resolve(); }) @@ -762,7 +758,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 2); assert.equal(params[0].totalApprovalWeight, "200.00002"); - assert.equal(params[0].totalEnabledApprovalWeight, "100.00001") transactions = []; transactions.push(new Transaction(37899124, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'tokens', 'stake', `{ "to": "ned", "symbol": "${CONSTANTS.GOVERNANCE_TOKEN_SYMBOL}", "quantity": "1", "isSignedWithActiveKey": true }`)); @@ -883,7 +878,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 2); assert.equal(params[0].totalApprovalWeight, "199.00002"); - assert.equal(params[0].totalEnabledApprovalWeight, "101.00001"); transactions = []; transactions.push(new Transaction(37899126, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'tokens', 'undelegate', `{ "from": "ned", "symbol": "${CONSTANTS.GOVERNANCE_TOKEN_SYMBOL}", "quantity": "2", "isSignedWithActiveKey": true }`)); @@ -966,7 +960,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 2); assert.equal(params[0].totalApprovalWeight, "197.00002"); - assert.equal(params[0].totalEnabledApprovalWeight, "99.00001"); transactions = []; transactions.push(new Transaction(37899127, fixture.getNextTxId(), 'harpagon', 'whatever', 'whatever', '')); @@ -1042,7 +1035,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 2); assert.equal(params[0].totalApprovalWeight, "201.00002"); - assert.equal(params[0].totalEnabledApprovalWeight, "101.00001"); transactions = []; transactions.push(new Transaction(37899128, fixture.getNextTxId(), 'ned', 'tokens', 'unstake', `{ "symbol": "${CONSTANTS.GOVERNANCE_TOKEN_SYMBOL}", "quantity": "1", "isSignedWithActiveKey": true }`)); @@ -1118,7 +1110,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 2); assert.equal(params[0].totalApprovalWeight, "200.75002"); - assert.equal(params[0].totalEnabledApprovalWeight, "100.75001"); transactions = []; transactions.push(new Transaction(37899129, fixture.getNextTxId(), 'harpagon', 'whatever', 'whatever', '')); @@ -1194,7 +1185,6 @@ describe('witnesses', function () { assert.equal(params[0].numberOfApprovedWitnesses, 2); assert.equal(params[0].totalApprovalWeight, "200.25002"); - assert.equal(params[0].totalEnabledApprovalWeight, "100.25001"); resolve(); }) @@ -1262,6 +1252,7 @@ describe('witnesses', function () { }); let schedule = res; + console.log(schedule); assert.equal(schedule[0].witness, "witness5"); assert.equal(schedule[0].blockNumber, 2); @@ -1294,7 +1285,6 @@ describe('witnesses', function () { let params = res; assert.equal(params.totalApprovalWeight, '3000.00000'); - assert.equal(params.totalEnabledApprovalWeight, '3000.00000'); assert.equal(params.numberOfApprovedWitnesses, 30); assert.equal(params.lastVerifiedBlockNumber, 1); assert.equal(params.currentWitness, 'witness7'); @@ -1487,209 +1477,10 @@ describe('witnesses', function () { i += 1; } - // Ensure witness who sent round got paid (last witness) - await tableAsserts.assertUserBalances({ account: schedules[schedules.length - 1].witness, symbol: CONSTANTS.UTILITY_TOKEN_SYMBOL, balance: "0", stake: "0.39954306" }); - - - // Ensure all witnesses did not get paid - for (i = 0; i < schedules.length - 1; i += 1) { - await tableAsserts.assertUserBalances({ account: schedules[i].witness, symbol: CONSTANTS.UTILITY_TOKEN_SYMBOL}); // Expecting no balance - } - - resolve(); - }) - .then(() => { - fixture.tearDown(); - done(); - }); - }); - - it('pays correct amount with reduced top witnesses', (done) => { - new Promise(async (resolve) => { - - await fixture.setUp(); - let transactions = []; - transactions.push(new Transaction(37899120, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'contract', 'update', JSON.stringify(tokensContractPayload))); - transactions.push(new Transaction(37899120, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'contract', 'update', JSON.stringify(inflationContractPayload))); - transactions.push(new Transaction(37899120, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'contract', 'deploy', JSON.stringify(miningContractPayload))); - transactions.push(new Transaction(37899120, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'contract', 'deploy', JSON.stringify(tokenfundsContractPayload))); - transactions.push(new Transaction(37899120, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'contract', 'deploy', JSON.stringify(nftauctionContractPayload))); - transactions.push(new Transaction(37899120, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'contract', 'deploy', JSON.stringify(witnessesContractPayload))); - addGovernanceTokenTransactions(fixture, transactions, 37899120); - transactions.push(new Transaction(37899120, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'tokens', 'stake', `{ "to": "${CONSTANTS.HIVE_ENGINE_ACCOUNT}", "symbol": "${CONSTANTS.GOVERNANCE_TOKEN_SYMBOL}", "quantity": "100", "isSignedWithActiveKey": true }`)); - transactions.push(new Transaction(37899120, fixture.getNextTxId(), 'null', 'tokens', 'issueToContract', `{ "to": "witnesses", "symbol": "${CONSTANTS.UTILITY_TOKEN_SYMBOL}", "quantity": "1000", "isSignedWithActiveKey": true, "callingContractInfo": { "name": "mining" } }`)); - - // register 100 witnesses - for (let index = 0; index < 100; index++) { - const witnessAccount = `witness${index}`; - const wif = dhive.PrivateKey.fromLogin(witnessAccount, 'testnet', 'active'); - transactions.push(new Transaction(37899120, fixture.getNextTxId(), witnessAccount, 'witnesses', 'register', `{ "IP": "123.123.123.${index}", "RPCPort": 5000, "P2PPort": 6000, "signingKey": "${wif.createPublic().toString()}", "enabled": true, "isSignedWithActiveKey": true }`)); - } - - let block = { - refHiveBlockNumber: 37899120, - refHiveBlockId: 'ABCD1', - prevRefHiveBlockId: 'ABCD2', - timestamp: '2018-06-01T00:00:00', - transactions, - }; - - await fixture.sendBlock(block); - await tableAsserts.assertNoErrorInLastBlock(); - - transactions = []; - for (let index = 0; index < 30; index++) { - transactions.push(new Transaction(99999999, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'witnesses', 'approve', `{ "witness": "witness${index + 5}", "isSignedWithActiveKey": true }`)); + for (i = 0; i < schedules.length; i += 1) { + await tableAsserts.assertUserBalances({ account: schedules[i].witness, symbol: CONSTANTS.UTILITY_TOKEN_SYMBOL, balance: "0", stake: "0.01902586" }); } - block = { - refHiveBlockNumber: 99999999, - refHiveBlockId: 'ABCD1', - prevRefHiveBlockId: 'ABCD2', - timestamp: '2018-06-01T00:00:00', - transactions, - }; - - await fixture.sendBlock(block); - await tableAsserts.assertNoErrorInLastBlock(); - - for (let i = 1; i < NB_WITNESSES; i++) { - transactions = []; - // send whatever transaction; - transactions.push(new Transaction(100000000 + i, fixture.getNextTxId(), 'satoshi', 'whatever', 'whatever', '')); - block = { - refHiveBlockNumber: 100000000 + i, - refHiveBlockId: 'ABCD1', - prevRefHiveBlockId: 'ABCD2', - timestamp: `2018-06-01T00:00:0${i}`, - transactions, - }; - - await fixture.sendBlock(block); - } - - // Change witnesses number mid block, which will reset the schedule. - transactions = []; - transactions.push(new Transaction(100000005, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'witnesses', 'updateParams', '{"numberOfTopWitnesses": 19, "numberOfWitnessSlots": 20, "witnessSignaturesRequired": 12}')); - block = { - refHiveBlockNumber: 100000005, - refHiveBlockId: 'ABCD1', - prevRefHiveBlockId: 'ABCD2', - timestamp: '2018-06-01T00:00:05', - transactions, - }; - - await fixture.sendBlock(block); - await tableAsserts.assertNoErrorInLastBlock(); - - let params = await fixture.database.findOne({ - contract: 'witnesses', - table: 'params', - query: {} - }); - - assert.equal(params.numberOfWitnessSlots, 20); - assert.equal(params.witnessSignaturesRequired, 12); - - // generate enough blocks to get to 20 - for (let i = NB_WITNESSES + 1; i < 20; i++) { - transactions = []; - // send whatever transaction; - transactions.push(new Transaction(100000000 + i, fixture.getNextTxId(), 'satoshi', 'whatever', 'whatever', '')); - block = { - refHiveBlockNumber: 100000000 + i, - refHiveBlockId: 'ABCD1', - prevRefHiveBlockId: 'ABCD2', - timestamp: `2018-06-01T00:00:0${i}`, - transactions, - }; - - await fixture.sendBlock(block); - } - - let blockNum = params.lastVerifiedBlockNumber + 1; - let endBlockRound = params.lastBlockRound; - - let calculatedRoundHash = ''; - // calculate round hash - while (blockNum <= endBlockRound) { - // get the block from the current node - const queryRes = await fixture.database.getBlockInfo(blockNum); - - const blockFromNode = queryRes; - if (blockFromNode !== null) { - calculatedRoundHash = SHA256(`${calculatedRoundHash}${blockFromNode.hash}`).toString(enchex); - } - blockNum += 1; - } - - res = await fixture.database.find({ - contract: 'witnesses', - table: 'schedules', - query: { - - } - }); - - let schedules = res; - assert(schedules.length > 0); - - let signatures = []; - schedules.forEach(schedule => { - const wif = dhive.PrivateKey.fromLogin(schedule.witness, 'testnet', 'active'); - const sig = signPayload(wif, calculatedRoundHash, true) - signatures.push([schedule.witness, sig]) - }); - - let json = { - round: 2, - roundHash: calculatedRoundHash, - signatures, - isSignedWithActiveKey: true, - }; - - transactions = []; - transactions.push(new Transaction(110000000, fixture.getNextTxId(), params.currentWitness, 'witnesses', 'proposeRound', JSON.stringify(json))); - - block = { - refHiveBlockNumber: 110000000, - refHiveBlockId: 'ABCD1', - prevRefHiveBlockId: 'ABCD2', - timestamp: '2018-06-01T00:00:11', - transactions, - }; - - await fixture.sendBlock(block); - await tableAsserts.assertNoErrorInLastBlock(); - - blockNum = params.lastVerifiedBlockNumber + 1; - - // check if the blocks are now marked as verified - let i = 0; - while (blockNum <= endBlockRound) { - // get the block from the current node - const queryRes = await fixture.database.getBlockInfo(blockNum); - - const blockFromNode = queryRes; - const wif = dhive.PrivateKey.fromLogin(blockFromNode.witness, 'testnet', 'active'); - assert.equal(blockFromNode.round, 2); - assert.equal(blockFromNode.witness, schedules[schedules.length - 1].witness); - assert.equal(blockFromNode.roundHash, calculatedRoundHash); - assert.equal(blockFromNode.signingKey, wif.createPublic().toString()); - assert.equal(blockFromNode.roundSignature, signatures[signatures.length - 1][1]); - blockNum += 1; - i += 1; - } - - // Ensure witness who sent round got paid (last witness) - await tableAsserts.assertUserBalances({ account: schedules[schedules.length - 1].witness, symbol: CONSTANTS.UTILITY_TOKEN_SYMBOL, balance: "0", stake: "0.38051720" }); - - - // Ensure all witnesses did not get paid - for (i = 0; i < schedules.length - 1; i += 1) { - await tableAsserts.assertUserBalances({ account: schedules[i].witness, symbol: CONSTANTS.UTILITY_TOKEN_SYMBOL}); // Expecting no balance - } - resolve(); }) .then(() => { @@ -1770,6 +1561,8 @@ describe('witnesses', function () { query: {} }); + console.log(params); + let blockNum = params.lastVerifiedBlockNumber + 1; const endBlockRound = params.lastBlockRound; @@ -1805,6 +1598,7 @@ describe('witnesses', function () { signatures, isSignedWithActiveKey: true, }; + console.log(json); transactions = []; refBlockNumber = fixture.getNextRefBlockNumber(); @@ -1841,7 +1635,6 @@ describe('witnesses', function () { }); assert.equal(params.totalApprovalWeight, '3000.00000'); - assert.equal(params.totalEnabledApprovalWeight, '3000.00000'); assert.equal(params.numberOfApprovedWitnesses, 30); assert.equal(params.lastVerifiedBlockNumber, 6); assert.equal(params.currentWitness, newSchedule[newSchedule.length - 1].witness); @@ -1914,7 +1707,6 @@ describe('witnesses', function () { let params = res; assert.equal(params.totalApprovalWeight, '3000.00000'); - assert.equal(params.totalEnabledApprovalWeight, '3000.00000'); assert.equal(params.numberOfApprovedWitnesses, 30); assert.equal(params.lastVerifiedBlockNumber, 1); assert.equal(params.currentWitness, 'witness6'); @@ -1952,7 +1744,7 @@ describe('witnesses', function () { params = res; - assert.equal(JSON.stringify(params), '{"_id":1,"totalApprovalWeight":"3000.00000","totalEnabledApprovalWeight":"3000.00000","numberOfApprovedWitnesses":30,"lastVerifiedBlockNumber":1,"round":1,"lastBlockRound":6,"currentWitness":"witness10","blockNumberWitnessChange":42,"lastWitnesses":["witness6","witness10"],"numberOfApprovalsPerAccount":30,"numberOfTopWitnesses":4,"numberOfWitnessSlots":5,"witnessSignaturesRequired":3,"maxRoundsMissedInARow":3,"maxRoundPropositionWaitingPeriod":20,"witnessApproveExpireBlocks":50}'); + assert.equal(JSON.stringify(params), '{"_id":1,"totalApprovalWeight":"3000.00000","numberOfApprovedWitnesses":30,"lastVerifiedBlockNumber":1,"round":1,"lastBlockRound":6,"currentWitness":"witness10","blockNumberWitnessChange":42,"lastWitnesses":["witness6","witness10"],"numberOfApprovalsPerAccount":30,"numberOfTopWitnesses":4,"numberOfWitnessSlots":5,"witnessSignaturesRequired":3,"maxRoundsMissedInARow":3,"maxRoundPropositionWaitingPeriod":20,"witnessApproveExpireBlocks":50}'); let schedule = await fixture.database.find({ contract: 'witnesses', @@ -2028,7 +1820,6 @@ describe('witnesses', function () { let params = res; assert.equal(params.totalApprovalWeight, '3000.00000'); - assert.equal(params.totalEnabledApprovalWeight, '3000.00000'); assert.equal(params.numberOfApprovedWitnesses, 30); assert.equal(params.lastVerifiedBlockNumber, 1); assert.equal(params.currentWitness, 'witness6'); @@ -2078,7 +1869,7 @@ describe('witnesses', function () { params = res; - assert.equal(JSON.stringify(params), '{"_id":1,"totalApprovalWeight":"3000.00000","totalEnabledApprovalWeight":"3000.00000","numberOfApprovedWitnesses":30,"lastVerifiedBlockNumber":1,"round":1,"lastBlockRound":6,"currentWitness":"witness10","blockNumberWitnessChange":42,"lastWitnesses":["witness6","witness10"],"numberOfApprovalsPerAccount":30,"numberOfTopWitnesses":4,"numberOfWitnessSlots":5,"witnessSignaturesRequired":3,"maxRoundsMissedInARow":1,"maxRoundPropositionWaitingPeriod":20,"witnessApproveExpireBlocks":50}'); + assert.equal(JSON.stringify(params), '{"_id":1,"totalApprovalWeight":"3000.00000","numberOfApprovedWitnesses":30,"lastVerifiedBlockNumber":1,"round":1,"lastBlockRound":6,"currentWitness":"witness10","blockNumberWitnessChange":42,"lastWitnesses":["witness6","witness10"],"numberOfApprovalsPerAccount":30,"numberOfTopWitnesses":4,"numberOfWitnessSlots":5,"witnessSignaturesRequired":3,"maxRoundsMissedInARow":1,"maxRoundPropositionWaitingPeriod":20,"witnessApproveExpireBlocks":50}'); let schedule = await fixture.database.find({ contract: 'witnesses', @@ -2128,11 +1919,11 @@ describe('witnesses', function () { query: {} }); - assert.equal(JSON.stringify(params), '{"_id":1,"totalApprovalWeight":"0","totalEnabledApprovalWeight":"0","numberOfApprovedWitnesses":0,"lastVerifiedBlockNumber":0,"round":0,"lastBlockRound":0,"currentWitness":null,"blockNumberWitnessChange":0,"lastWitnesses":[],"numberOfApprovalsPerAccount":30,"numberOfTopWitnesses":4,"numberOfWitnessSlots":5,"witnessSignaturesRequired":3,"maxRoundsMissedInARow":3,"maxRoundPropositionWaitingPeriod":20,"witnessApproveExpireBlocks":50}'); + assert.equal(JSON.stringify(params), '{"_id":1,"totalApprovalWeight":"0","numberOfApprovedWitnesses":0,"lastVerifiedBlockNumber":0,"round":0,"lastBlockRound":0,"currentWitness":null,"blockNumberWitnessChange":0,"lastWitnesses":[],"numberOfApprovalsPerAccount":30,"numberOfTopWitnesses":4,"numberOfWitnessSlots":5,"witnessSignaturesRequired":3,"maxRoundsMissedInARow":3,"maxRoundPropositionWaitingPeriod":20,"witnessApproveExpireBlocks":50}'); transactions = []; refBlockNumber = fixture.getNextRefBlockNumber(); - transactions.push(new Transaction(refBlockNumber, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'witnesses', 'updateParams', '{"totalApprovalWeight":"1","totalEnabledApprovalWeight":"1","numberOfApprovedWitnesses":1,"lastVerifiedBlockNumber":1,"round":1,"lastBlockRound":1,"currentWitness":"ignore","blockNumberWitnessChange":1,"lastWitnesses":["ignore"],"maxRoundPropositionWaitingPeriod":21,"maxRoundsMissedInARow":4,"numberOfApprovalsPerAccount":31,"numberOfTopWitnesses":5,"numberOfWitnessSlots":6,"witnessSignaturesRequired":16,"witnessApproveExpireBlocks":100}')); + transactions.push(new Transaction(refBlockNumber, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'witnesses', 'updateParams', '{"totalApprovalWeight":"1","numberOfApprovedWitnesses":1,"lastVerifiedBlockNumber":1,"round":1,"lastBlockRound":1,"currentWitness":"ignore","blockNumberWitnessChange":1,"lastWitnesses":["ignore"],"maxRoundPropositionWaitingPeriod":21,"maxRoundsMissedInARow":4,"numberOfApprovalsPerAccount":31,"numberOfTopWitnesses":5,"numberOfWitnessSlots":6,"witnessSignaturesRequired":16,"witnessApproveExpireBlocks":100}')); block = { refHiveBlockNumber: refBlockNumber, @@ -2151,13 +1942,13 @@ describe('witnesses', function () { query: {} }); - const paramsString = '{"_id":1,"totalApprovalWeight":"0","totalEnabledApprovalWeight":"0","numberOfApprovedWitnesses":0,"lastVerifiedBlockNumber":0,"round":0,"lastBlockRound":0,"currentWitness":null,"blockNumberWitnessChange":0,"lastWitnesses":[],"numberOfApprovalsPerAccount":31,"numberOfTopWitnesses":5,"numberOfWitnessSlots":6,"witnessSignaturesRequired":16,"maxRoundsMissedInARow":4,"maxRoundPropositionWaitingPeriod":21,"witnessApproveExpireBlocks":100}'; + const paramsString = '{"_id":1,"totalApprovalWeight":"0","numberOfApprovedWitnesses":0,"lastVerifiedBlockNumber":0,"round":0,"lastBlockRound":0,"currentWitness":null,"blockNumberWitnessChange":0,"lastWitnesses":[],"numberOfApprovalsPerAccount":31,"numberOfTopWitnesses":5,"numberOfWitnessSlots":6,"witnessSignaturesRequired":16,"maxRoundsMissedInARow":4,"maxRoundPropositionWaitingPeriod":21,"witnessApproveExpireBlocks":100}'; assert.equal(JSON.stringify(params), paramsString); // Verify 1 backup witness condition in setting transactions = []; refBlockNumber = fixture.getNextRefBlockNumber(); - transactions.push(new Transaction(refBlockNumber, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'witnesses', 'updateParams', '{"totalApprovalWeight":"2","totalEnabledApprovalWeight":"2","numberOfApprovedWitnesses":2,"lastVerifiedBlockNumber":2,"round":2,"lastBlockRound":2,"currentWitness":"ignore","blockNumberWitnessChange":2,"lastWitnesses":["ignore"],"maxRoundPropositionWaitingPeriod":22,"maxRoundsMissedInARow":5,"numberOfApprovalsPerAccount":32,"numberOfTopWitnesses":6,"numberOfWitnessSlots":6,"witnessSignaturesRequired":17}')); + transactions.push(new Transaction(refBlockNumber, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'witnesses', 'updateParams', '{"totalApprovalWeight":"2","numberOfApprovedWitnesses":2,"lastVerifiedBlockNumber":2,"round":2,"lastBlockRound":2,"currentWitness":"ignore","blockNumberWitnessChange":2,"lastWitnesses":["ignore"],"maxRoundPropositionWaitingPeriod":22,"maxRoundsMissedInARow":5,"numberOfApprovalsPerAccount":32,"numberOfTopWitnesses":6,"numberOfWitnessSlots":6,"witnessSignaturesRequired":17}')); block = { refHiveBlockNumber: refBlockNumber, @@ -2186,7 +1977,7 @@ describe('witnesses', function () { // Verify witnessApproveExpireBlocks > numberOfWitnessSlots transactions = []; refBlockNumber = fixture.getNextRefBlockNumber(); - transactions.push(new Transaction(refBlockNumber, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'witnesses', 'updateParams', '{"totalApprovalWeight":"1","totalEnabledApprovalWeight":"1","numberOfApprovedWitnesses":1,"lastVerifiedBlockNumber":1,"round":1,"lastBlockRound":1,"currentWitness":"ignore","blockNumberWitnessChange":1,"lastWitnesses":["ignore"],"maxRoundPropositionWaitingPeriod":21,"maxRoundsMissedInARow":4,"numberOfApprovalsPerAccount":31,"numberOfTopWitnesses":5,"numberOfWitnessSlots":6,"witnessSignaturesRequired":16,"witnessApproveExpireBlocks":1}')); + transactions.push(new Transaction(refBlockNumber, fixture.getNextTxId(), CONSTANTS.HIVE_ENGINE_ACCOUNT, 'witnesses', 'updateParams', '{"totalApprovalWeight":"1","numberOfApprovedWitnesses":1,"lastVerifiedBlockNumber":1,"round":1,"lastBlockRound":1,"currentWitness":"ignore","blockNumberWitnessChange":1,"lastWitnesses":["ignore"],"maxRoundPropositionWaitingPeriod":21,"maxRoundsMissedInARow":4,"numberOfApprovalsPerAccount":31,"numberOfTopWitnesses":5,"numberOfWitnessSlots":6,"witnessSignaturesRequired":16,"witnessApproveExpireBlocks":1}')); block = { refHiveBlockNumber: refBlockNumber, @@ -2276,7 +2067,6 @@ describe('witnesses', function () { let params = res; assert.equal(params.totalApprovalWeight, '3000.00000'); - assert.equal(params.totalEnabledApprovalWeight, '3000.00000'); assert.equal(params.numberOfApprovedWitnesses, 30); assert.equal(params.lastVerifiedBlockNumber, 1); assert.equal(params.currentWitness, 'witness6'); @@ -2323,20 +2113,10 @@ describe('witnesses', function () { } }); + for (const witness of res) { assert.match(witness.approvalWeight["$numberDecimal"], /(0.0000|0)/) //Ensure all votes are gone } - - res = await fixture.database.findOne({ - contract: 'witnesses', - table: 'params', - query: { - - } - }); - params = res; - assert.equal(params.totalApprovalWeight, '0.00000'); - assert.equal(params.totalEnabledApprovalWeight, '0.00000'); resolve(); }) .then(() => { @@ -2426,7 +2206,6 @@ describe('witnesses', function () { let params = res; assert.equal(params.totalApprovalWeight, '299.90000'); - assert.equal(params.totalEnabledApprovalWeight, '299.90000'); assert.equal(params.numberOfApprovedWitnesses, 2999); assert.equal(params.lastVerifiedBlockNumber, 2); assert.equal(params.currentWitness, 'witness2'); @@ -2483,17 +2262,6 @@ describe('witnesses', function () { for (const witness of res) { assert.match(witness.approvalWeight["$numberDecimal"], /(0.0000|0)/) //Ensure all votes are gone } - res = await fixture.database.findOne({ - contract: 'witnesses', - table: 'params', - query: { - - } - }); - - params = res; - assert.equal(params.totalApprovalWeight, '0.00000'); - assert.equal(params.totalEnabledApprovalWeight, '0.00000'); resolve(); }) .then(() => {