Skip to content

Commit

Permalink
Merge pull request #96 from dtube/hf6
Browse files Browse the repository at this point in the history
HF6 "Space Odyssey"
  • Loading branch information
techcoderx authored Jun 28, 2022
2 parents 3b82151 + 916dbbc commit 01c27a2
Show file tree
Hide file tree
Showing 42 changed files with 1,628 additions and 69 deletions.
2 changes: 1 addition & 1 deletion doc/syncing-your-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This is the fastest method that reverifies locally all the past blocks and trans

```bash
cd /path/to/blocks/dir
wget -c https://backup.d.tube/dump/avalon/blocks.bson
wget -c https://backup.d.tube/blocks.bson
cd /path/to/avalon/directory
REBUILD_STATE=1 ./scripts/start.sh
```
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "avalon",
"version": "1.5.2",
"version": "1.6",
"description": "",
"scripts": {
"start": "node src/main.js",
Expand Down Expand Up @@ -54,7 +54,7 @@
"name": "Avalon",
"title": "Avalon API Documentation",
"description": "REST API documentation for Avalon blockchain",
"sampleUrl": "https://avalon.oneloved.tube",
"sampleUrl": "https://api.avalonblocks.com",
"version": "1.6.0"
},
"devDependencies": {
Expand Down
21 changes: 14 additions & 7 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ let cache = {
accounts: {},
contents: {},
distributed: {},
playlists: {}
proposals: {},
playlists: {},
masterdao: {},
state: {}
},
accounts: {},
contents: {},
distributed: {},
proposals: {},
playlists: {},
masterdao: {},
state: {},
changes: [],
inserts: [],
rebuild: {
Expand Down Expand Up @@ -54,10 +60,9 @@ let cache = {
return new Promise((rs,rj) => cache.findOne(collection,query,(e,d) => e ? rj(e) : rs(d)))
},
findOne: function(collection, query, cb) {
if (['accounts','blocks','contents','playlists'].indexOf(collection) === -1) {
cb(true)
return
}
if (!cache.copy[collection])
return cb('invalid collection')

let key = cache.keyByCollection(collection)
// searching in cache
if (cache[collection][query[key]]) {
Expand All @@ -83,6 +88,9 @@ let cache = {
}
})
},
updateOnePromise: function (collection, query, changes) {
return new Promise((rs,rj) => cache.updateOne(collection,query,changes,(e,d) => e ? rj(e) : rs(true)))
},
updateOne: function(collection, query, changes, cb) {
cache.findOne(collection, query, function(err, obj) {
if (err) throw err
Expand Down Expand Up @@ -306,7 +314,6 @@ let cache = {
switch (collection) {
case 'accounts':
return 'name'

default:
return '_id'
}
Expand Down Expand Up @@ -363,4 +370,4 @@ let cache = {
})
}

module.exports = cache
module.exports = cache
34 changes: 28 additions & 6 deletions src/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const secp256k1 = require('secp256k1')
const bs58 = require('base-x')(config.b58Alphabet)
const series = require('run-series')
const cloneDeep = require('clone-deep')
const dao = require('./dao')
const daoMaster = require('./daoMaster')
const transaction = require('./transaction.js')
const notifications = require('./notifications.js')
const txHistory = require('./txHistory')
Expand Down Expand Up @@ -123,16 +125,18 @@ let chain = {
// so we will execute transactions in order and revalidate after each execution
chain.executeBlockTransactions(newBlock, true, false, function(validTxs, distributed, burned) {
cache.rollback()
dao.resetID()
daoMaster.resetID()
// and only add the valid txs to the new block
newBlock.txs = validTxs

if (distributed) newBlock.dist = distributed
if (burned) newBlock.burn = burned

// always record the failure of others
if (chain.schedule.shuffle[(newBlock._id-1)%config.leaders].name !== process.env.NODE_OWNER)
newBlock.missedBy = chain.schedule.shuffle[(newBlock._id-1)%config.leaders].name

if (distributed) newBlock.dist = distributed
if (burned) newBlock.burn = burned

// hash and sign the block with our private key
newBlock = chain.hashAndSignBlock(newBlock)

Expand Down Expand Up @@ -256,6 +260,8 @@ let chain = {
chain.applyHardforkPostBlock(block._id)
eco.appendHistory(block)
eco.nextBlock()
dao.nextBlock()
daoMaster.nextBlock()
leaderStats.processBlock(block)
txHistory.processBlock(block)

Expand Down Expand Up @@ -434,6 +440,8 @@ let chain = {
isValidBlockTxs: (newBlock, cb) => {
chain.executeBlockTransactions(newBlock, true, false, function(validTxs) {
cache.rollback()
dao.resetID()
daoMaster.resetID()
if (validTxs.length !== newBlock.txs.length) {
logr.error('invalid block transaction')
cb(false); return
Expand Down Expand Up @@ -619,11 +627,15 @@ let chain = {
// execute periodic burn
let additionalBurn = await chain.decayBurnAccount(block)

// execute dao triggers
let daoBurn = await dao.runTriggers(block.timestamp)

// add rewards for the leader who mined this block
chain.leaderRewards(block.miner, block.timestamp, function(dist) {
distributedInBlock += dist
distributedInBlock = Math.round(distributedInBlock*1000) / 1000
burnedInBlock += additionalBurn
burnedInBlock += daoBurn
burnedInBlock = Math.round(burnedInBlock*1000) / 1000
cb(executedSuccesfully, distributedInBlock, burnedInBlock)
})
Expand Down Expand Up @@ -795,8 +807,7 @@ let chain = {
applyHardfork: (block,cb) => {
// Do something on hardfork block after tx executions and before leader rewards distribution
// As this is not a real transaction, no actual transaction is considered executed here
// NOTE: Update block height to actual HF block activation
if (block._id === 25000000)
if (block._id === 17150000)
// Clear @dtube.airdrop account
cache.findOne('accounts', {name: config.burnAccount}, (e,burnAccount) => {
let burned = burnAccount.balance
Expand All @@ -806,7 +817,16 @@ let chain = {
balance: 0,
bw: { v: 0, t: block.timestamp },
vt: { v: 0, t: block.timestamp }
}}, () => cb(null, { executed: false, distributed: 0, burned: burned }))
}}, () =>
// disable @dtube leader
transaction.execute({
type: 18,
data: {
pub: ''
},
sender: 'dtube'
},block.timestamp,() => cb(null, { executed: false, distributed: 0, burned: burned }))
)
})
else
cb(null, { executed: false, distributed: 0, burned: 0 })
Expand Down Expand Up @@ -874,6 +894,8 @@ let chain = {
// update the config if an update was scheduled
config = require('./config.js').read(blockToRebuild._id)
chain.applyHardforkPostBlock(blockToRebuild._id)
dao.nextBlock()
daoMaster.nextBlock()
eco.nextBlock()
eco.appendHistory(blockToRebuild)
chain.cleanMemory()
Expand Down
139 changes: 139 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ program.command('account-revoke <user> <id>')
writeLine(' $ account-revoke bob finance -F key.json -M alice')
})

program.command('chainupdate-create <title> <description> <url> <changes>')
.description('create a new chain update proposal')
.action(function(title, description, url, changes) {
verifyAndSendTx('chainUpdateCreate', title, description, url, changes)
}).on('--help', function(){
writeLine('')
writeLine('Arguments:')
writeLine(' <title>: proposal title')
writeLine(' <description>: proposal description')
writeLine(' <url>: proposal reference url')
writeLine(' <changes>: array of 2-element key-value arrays of proposed parameter changes')
writeLine('')
writeLine('Examples:')
writeLine(' $ chainupdate-create \'An example chain update title\' \'Some description to describe it\' \'https://d.tube/#!/v/alice/chain-update-proposal\' [["vtPerBurn",100],["rewardPoolAmount",100000]] -F key.json -M alice')
})

program.command('claim <author> <link>')
.description('claims rewards associated with a past vote')
.action(function(author, link) {
Expand Down Expand Up @@ -159,6 +175,67 @@ program.command('follow <target>')
writeLine(' $ follow bob -F key.json -M alice')
})

program.command('fundrequest-create <title> <description> <url> <requested> <receiver>')
.description('create a new funding request')
.action(function(title, description, url, requested, receiver) {
verifyAndSendTx('fundRequestCreate', title, description, url, requested, receiver)
}).on('--help', function(){
writeLine('')
writeLine('Arguments:')
writeLine(' <title>: proposal title')
writeLine(' <description>: proposal description')
writeLine(' <url>: proposal reference url')
writeLine(' <requested>: requested amount for this fund request')
writeLine(' <receiver>: beneficiary of the fund request')
writeLine('')
writeLine('Examples:')
writeLine(' $ fundrequest-create \'An example proposal title\' \'Some description to describe it\' \'https://d.tube/#!/v/alice/proposal-video\' 10000 alice -F key.json -M alice')
})

program.command('fundrequest-contrib <id> <amount>')
.description('contribute to a funding request')
.action(function(id, amount) {
verifyAndSendTx('fundRequestContrib', id, amount)
}).on('--help', function(){
writeLine('')
writeLine('Arguments:')
writeLine(' <id>: id of the fund request proposal')
writeLine(' <amount>: amount to contribute')
writeLine('')
writeLine('Examples:')
writeLine(' $ fundrequest-contrib 1 50000 -F key.json -M john')
})

program.command('fundrequest-work <id> <work>')
.description('submit work details to a fund request for review')
.action(function(id, work) {
verifyAndSendTx('fundRequestWork', id, work)
}).on('--help', function(){
writeLine('')
writeLine('Arguments:')
writeLine(' <id>: id of the fund request proposal')
writeLine(' <work>: json work details')
writeLine('')
writeLine('Examples:')
writeLine(' $ fundrequest-work 1 \'{"work":"this is some work for a proposal, more details in a url."}\' -F key.json -M alice')
})

program.command('fundrequest-work-review <id> <approve> <memo>')
.alias('fundrequest-review')
.description('submit review details of work related to fund request')
.action(function(id, approve, memo) {
verifyAndSendTx('fundRequestWorkReview', id, approve, memo)
}).on('--help', function(){
writeLine('')
writeLine('Arguments:')
writeLine(' <id>: id of the fund request proposal')
writeLine(' <approve>: boolean value to approve or disapprove work')
writeLine(' <memo>: feedback for work done')
writeLine('')
writeLine('Examples:')
writeLine(' $ fundrequest-work-review 1 true \'some feedback here\' -F key.json -M alice')
})

program.command('keypair')
.description('generate a new keypair')
.alias('key')
Expand Down Expand Up @@ -230,6 +307,34 @@ program.command('limit-vt')
writeLine(' $ limit-vt -1 -F key.json -M alice')
})

program.command('md-queue <txtype> <payload>')
.description('queue a transaction in master dao')
.action(function(txtype, payload) {
verifyAndSendTx('mdQueue', txtype, payload)
}).on('--help', function(){
writeLine('')
writeLine('Arguments:')
writeLine(' <txtype>: the transaction type to be queued')
writeLine(' <payload>: the payload of the new transaction to be queued')
writeLine('')
writeLine('Examples:')
writeLine(' $ mdqueue 6 \'{"json":{"foo":"bar"}}\' -F key.json -M bob')
writeLine(' $ mdqueue 32 \'{"id":2,"amount":10000}\' -F key.json -M john')
})

program.command('md-sign <id>')
.description('approve a queued transaction in master dao')
.action(function(id) {
verifyAndSendTx('mdSign', id)
}).on('--help', function(){
writeLine('')
writeLine('Arguments:')
writeLine(' <id>: identifier of the queued transaction')
writeLine('')
writeLine('Examples:')
writeLine(' $ mdqueue 1 -F key.json -M alice')
})

program.command('new-key <id> <pub> <allowed_txs>')
.description('add new key with custom perms')
.action(function(id, pub, allowedTxs) {
Expand Down Expand Up @@ -370,6 +475,40 @@ program.command('promote <link> <pa> <pp> <json> <vt> <tag> <burn>')
writeLine(' $ promote big-video \'\' \'\' \'{"title": "Check this out"}\' 777 my-tag 10 -F key.json -M alice')
})

program.command('proposal-vote <id> <amount>')
.alias('dao-vote')
.description('vote for a dao proposal')
.action(function(id, amount) {
verifyAndSendTx('proposalVote', id, amount)
}).on('--help', function(){
writeLine('')
writeLine('Arguments:')
writeLine(' <id>: the identifier of the dao proposal to vote on')
writeLine(' <amount>: voting weight for the vote. <amount> tokens will be locked until voting period ends.')
writeLine('')
writeLine('Examples:')
writeLine(' $ dao-vote 2 5000000 -F key.json -M bob')
writeLine(' $ proposal-vote 3 2000000 -F key.json -M john')
})

program.command('proposal-edit <id> <title> <description> <url>')
.alias('dao-edit')
.description('edit metadata of a dao proposal')
.action(function(id, title, description, url) {
verifyAndSendTx('proposalEdit', id, title, description, url)
}).on('--help', function(){
writeLine('')
writeLine('Arguments:')
writeLine(' <id>: the identifier of the dao proposal to edit metadata of')
writeLine(' <title> updated title of proposal')
writeLine(' <description> updated description of proposal')
writeLine(' <url> updated url of proposal')
writeLine('')
writeLine('Examples:')
writeLine(' $ dao-vote 2 \'Updated proposal title\' \'Edited escription with some more details\' \'https://d.tube/#!/v/bob/updated-proposal-video\' -F key.json -M bob')
writeLine(' $ proposal-vote 3 \'Updated proposal title\' \'Edited escription with some more details\' \'https://d.tube/#!/v/john/work-update\' -F key.json -M john')
})

program.command('public')
.description('get public key from private key')
.action(function() {
Expand Down
Loading

0 comments on commit 01c27a2

Please sign in to comment.