-
Notifications
You must be signed in to change notification settings - Fork 1
/
vars.go
94 lines (76 loc) · 3.06 KB
/
vars.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"crypto/rsa"
"io"
"sync"
"time"
"github.com/kchristidis/island/bidder"
"github.com/kchristidis/island/blockchain"
"github.com/kchristidis/island/blocknotifier"
"github.com/kchristidis/island/regulator"
"github.com/kchristidis/island/slotnotifier"
"github.com/kchristidis/island/stats"
"github.com/kchristidis/island/trace"
)
// The files that this simulation will write to for metrics/plotting.
const (
OutputDir = "output"
OutputTran = "tran.csv"
OutputSlot = "slot.csv"
OutputBlock = "block.csv"
)
// BidderCount counts the number of bidders we have in the system.
const BidderCount = trace.IDCount
// StatChannelBuffer sets the buffer of the channels we use to pipe metrics into the
// stats collector from the agents. The larger the buffer of those channels, the less
// chances the stats collector will block when aggregating stats.
const StatChannelBuffer = 100
var (
err error
// Which iteration is this? Used to name the files we're writing results to.
iter int
// The prefix for all `Output*` files above
outputPrefix string
// Track the duration of a simulation
timeStart time.Time
bidders [BidderCount]*bidder.Bidder
regtor *regulator.Regulator
bNotifiers []*blocknotifier.Notifier
sNotifiers []*slotnotifier.Notifier
sdkctx *blockchain.SDKContext
// How many blocks constitute a slot? A sensitivity analysis parameter.
blocksPerSlot int
// The delay in blocks between the signal to PostKey and the signal to MarkEnd.
// A sensitivity analysis parameter.
blockOffset int
// How often do we issue the Clock call to help with the creation of new blocks?
clockPeriod time.Duration
// How often do we check for new blocks?
sleeDduration time.Duration
// Upon receiving this block, the markend slot notifier will send its first signal,
// and the whole thing will get going. The optional second slot notifier will be
// triggered upon receiving block <startFromBlock>+<blockOffset>.
startFromBlock uint64
// Key pairs for the agents
// N.B. For this PoC, have all agents use the same key-pair. This works just fine for
// our time-based measurements. In an actual deployment, each agent would use their own keys.
privKey *rsa.PrivateKey
// The original trace is converted into this typed structure for easier processing
traceMap map[int][][]float64
// The channel(s) on which notifications are received from the block notifier(s)
slotCs []chan int
// The typed conduits for agents to pipe metrics into the stats collector
statsBlockC chan stats.Block
statsSlotC chan stats.Slot
statsTranC chan stats.Transaction
statsCollector *stats.Collector
doneC chan struct{} // Acts as a coordination signal for goroutines
once sync.Once // Ensures that donec is only closed once.
doneStatsC chan struct{} // We want to terminate the stats collector *after* all the stat-submitting goroutines have returned.
// Waitgroups for goroutine coordination
// - wg1: bidders
// - wg2: regulators, block/slot notifiers
// - wg3: stats collector
wg1, wg2, wg3 sync.WaitGroup
writer io.Writer // For logging
)