Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Moneypot simulation #15

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions stats/big-simulation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
let Simulation = require('./simulation')
let modules = require('./strategies')
let feeRate = 56 * 100
let results = []

let list = require('./moneypot-hotwallet.json')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename this to data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to name it like this so more data can be added eventually


// for each strategy
for (var name in modules) {
let f = modules[name]
let simulation = new Simulation(name, f, feeRate)

console.log(name)
let i = 0
for (var value of list) {
i++

if (i % 1000 === 0) {
console.log(i)
}
let txo = {
address: 'A',
value: Math.abs(value)
Copy link
Contributor Author

@karelbilek karelbilek Jul 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't merge this yet. There is a bug; because this has no script, simulation.js thinks this is a change output (if it's being sent), so all utxos are always returned back to the "wallet". solved

Copy link
Contributor Author

@karelbilek karelbilek Jul 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly - I am a little stuck on the {script: {length}} now.

It is used both in utxos and txos in simulation.js; however, it is also used in utils.outputbytes for both inputs and outputs! So both input script size and output script sizes are the same in the simulations, which makes the results wrong :)

solved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(OK, I thought coin selection simulation will be a quick task, and it takes me quite a while. :D Luckily, I have two different implementations, one here and one in scala, and I am looking at where they differ :D )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries.
As for the merge, I don't mind master being a development branch here.
Happy to keep development in the PR if you are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer development in PRs too

}

if (value > 0) {
simulation.addUTXO(txo)
} else {
simulation.run([txo])
}
}

simulation.finish()
results.push(simulation)
}

Simulation.printResults(Simulation.mergeResults(results))
57 changes: 1 addition & 56 deletions stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,59 +36,4 @@ for (var j = 0; j < 100; ++j) {
}
}

function merge (results) {
let resultMap = {}

results.forEach(({ stats }) => {
let result = resultMap[stats.name]

if (result) {
result.inputs += stats.inputs
result.outputs += stats.outputs
result.transactions += stats.transactions
result.failed += stats.failed
result.fees += stats.fees
result.bytes += stats.bytes
result.utxos += stats.utxos
result.average = {
nInputs: result.inputs / result.transactions,
nOutputs: result.outputs / result.transactions,
fee: Math.round(result.fees / result.transactions),
feeRate: Math.round(result.fees / result.bytes)
}
result.totalCost += stats.totalCost
} else {
resultMap[stats.name] = Object.assign({}, stats)
}
})

return Object.keys(resultMap).map(k => ({ stats: resultMap[k] }))
}

function pad (i) {
if (typeof i === 'number') i = Math.round(i * 1000) / 1000
return (' ' + i).slice(-10)
}

merge(results).sort((a, b) => {
if (a.stats.transactions !== b.stats.transactions) return b.stats.transactions - a.stats.transactions
return a.stats.totalCost - b.stats.totalCost

// top 20 only
}).slice(0, 20).forEach((x, i) => {
let { stats } = x
let DNF = stats.failed / (stats.transactions + stats.failed)

console.log(
pad(i),
pad(stats.name),
'| transactions', pad('' + stats.transactions),
'| fee', pad('' + stats.average.fee),
'| feeRate', pad('' + stats.average.feeRate),
'| nInputs', pad(stats.average.nInputs),
'| nOutputs', pad(stats.average.nOutputs),
'| DNF', (100 * DNF).toFixed(2) + '%',
'| totalCost', pad('' + Math.round(stats.totalCost / 1000)),
'| utxos', pad('' + stats.utxos)
)
})
Simulation.printResults(Simulation.mergeResults(results))
Loading