forked from iadix/purenode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodix.node
334 lines (255 loc) · 10.6 KB
/
nodix.node
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
let NODE_GFX_OBJECT configuration = `
{
"name":"nodix",
"seed_node" :
{
"host":"nodix.eu",
"port" : 16819
},
"magic":0xD9BEFECA,
"pubKeyVersion":0x19,
(NODE_MODULE_DEF) "sign_mod" : {"file":"modz/ecdsa.tpo"},
"staking":
{
"targetspacing":64,
"maxtargetspacing" : 640,
"targettimespan":960,
"limit":0x1B00FFFF,
"minStakeDepth":2,
"reward" : 150000000,
(NODE_MODULE_DEF) "pos_kernel" : {"file":"modz/stake_pos3.tpo"}
},
"mining":
{
"targetspacing":64,
"maxtargetspacing" : 640,
"targettimespan":960,
"limit":0x1E0FFFFF,
"reward":10000000000000,
"last_pow_block":200000,
"txfee":10000
},
"genesis":
{
"version" :1,
"time" :1466419085,
"bits" :0x1e0fffff,
"nonce" :579883,
"InitialStakeModifier":0,
"InitialStakeModifier2":0
}
}`
let NODE_BITCORE_NODE SelfNode = `
{
"user_agent" : "nodix",
"privKeyVersion":0x55,
(NODE_GFX_BINT)"paytxfee" : 0,
"block_height" : 0,
"useGC" : false,
(NODE_GFX_INT)"version" : 60018,
(NODE_GFX_BOOL)"uPnP":true,
(NODE_GFX_INT)"bestChainDepth":2,
(NODE_GFX_INT)"maxMsgSize":1024,
(NODE_GFX_INT)"maxFileSize":4096,
(NODE_GFX_INT)"checktxsign" : 0,
(NODE_GFX_INT)"next_check" : 0,
(NODE_GFX_INT)"scriptBlock" : 0,
(NODE_GFX_INT)"current_pos_diff" : 0,
(NODE_GFX_INT)"current_pow_diff" : 0,
(NODE_GFX_BINT)"pos_reward" : 0,
(NODE_GFX_BINT)"pow_reward" : 0,
(NODE_GFX_BINT)"n_pow_blocks" : 0,
(NODE_GFX_INT)"mempool_lck" : 0,
(NODE_GFX_SIGNED_BINT)"ping_delay" : 0,
(NODE_GFX_INT)"last_block_time" : 0,
(NODE_BITCORE_BLK_HDR) "last_block" : {},
(NODE_BITCORE_BLK_HDR) "lastPOSBlk" : {},
(NODE_BITCORE_BLK_HDR) "lastPOWBlk" : {},
(NODE_GFX_OBJECT) "trustedApps": { "blog" : true, "raytrace" : true, "Cards" : true, "NodixSite" : true },
(NODE_BITCORE_ADDR)"p2p_addr" :
{
"services": 0,
(NODE_NET_IP)"addr" : "127.0.0.1",
(NODE_GFX_SHORT)"port" : 8000
},
(NODE_BITCORE_NODE_LIST) "peer_nodes" : [],
(NODE_BITCORE_WALLET_ADDR_LIST) "addr scan list" : null,
(NODE_BITCORE_MSG_LIST) "send queue" : [],
(NODE_BITCORE_MSG_LIST) "emitted_queue" : [],
(NODE_BITCORE_TX_LIST) "mempool" : [],
(NODE_BITCORE_TX_LIST) "submitted txs" : [],
(NODE_JSON_ARRAY) "pending files" : [],
(NODE_BITCORE_BLOCK_LIST) "submitted blocks" : []
}`
let NODE_SERVICE stratum_service = `
{
"port" : 10000,
(NODE_NET_IP)"addr" : "127.0.0.1",
"name" : "Nodix stratum service",
"mining_addr":"BH6o52jv2SjzCfmQmKRACFEAxooo2UF47A",
"difficulty" : 0x1D000FFF,
(NODE_MODULE_DEF) "module" : {"file":"modz/stratum_service.tpo"}
} `
let NODE_SERVICE http_service = `
{
"ports" : [{"port" : 16820, "data": {}}],
(NODE_NET_IP)"addr" : "127.0.0.1",
"docroot" : "web",
"apppath" : "/app/",
"useThread" : true,
"name" : "Nodix webservice",
(NODE_MODULE_DEF) "module" : {"file":"modz/http_service.tpo"},
"indexpage" : "/app/NodixSite/page/index.site",
"mimes" : {"js":"text/javascript", "css" : "text/css", "woff" : "text/css", "woff2" : "text/css", "png" : "image/png", "pdf" : "application/pdf", "gif" : "image/gif", "mpg":"video/mpeg", "mp4":"video/mp4", "svg" : "image/svg+xml", "html" : "text/html" , "obj":"application/object", "wav":"audio/wave"},
"defaultmime" : "text/plain",
"cacheTime" : 0,
"nthreads" : 4,
"maxpost" : 4096,
"sitemap" :
{
path : "/sitemap.xml"
},
"modules" :
[
{"base" : "/jsonrpc/" , "type" : "rpc", (NODE_MODULE_DEF) "rpc_wallet" : {"file":"modz/rpc_wallet.tpo"}},
{"base" : "/pubwal" , "allowed_ip":["127.0.0.1"] , "type" : "rpc", (NODE_MODULE_DEF) "anon_wallet" : {"file":"modz/anon_rpc.tpo"}},
{"base" : "/api/" , "type" : "cgi", (NODE_MODULE_DEF) "block_explorer" : {"file":"modz/block_explorer.tpo"}},
{"base" : "/siteapi/" , "type" : "cgi", (NODE_MODULE_DEF) "site_cgi" : {"file":"modz/site_cgi.tpo"}}
]
} `
let NODE_MODULE_DEF vec = `{"order":0, "file" : "modz/vec3.tpo"}`
let NODE_MODULE_DEF protocol_adx = `{"order":1, "file" : "modz/protocol_adx.tpo"}`
let NODE_MODULE_DEF block_adx = `{"order":2, "file" : "modz/block_adx.tpo"}`
let NODE_MODULE_DEF wallet = `{"order":3, "file" : "modz/wallet.tpo"}`
let NODE_MODULE_DEF node_adx = `{"order":4, "file" : "modz/node_adx.tpo"}`
let NODE_MODULE_DEF nodix = `{"order":5, "file" : "modz/nodix.tpo"}`
let NODE_BITCORE_BLK_HDR genesis_blk = `{}`
let NODE_GFX_INT ping_nonce = 1
let NODE_GFX_BINT block_reward = 0
let NODE_GFX_BINT lost_reward = 0
let NODE_GFX_BINT cur_len = 0
let NODE_GFX_BINT checkNum = 200
let NODE_GFX_BINT LastGood = 0
let NODE_GFX_SHORT one = 1
let NODE_BITCORE_HASH_LIST hash_list = `[]`
accumulator add_reward = `
block_adx.block_has_pow(SelfNode.block_index[accum_idx]) :
configuration.staking.pos_kernel.stake_get_reward(accum_idx, block_reward) : error endor
accum block_reward;
success
endor
accum configuration.mining.reward;
success
`
handler on_verack(node,payload) = ` node_adx.queue_ping_message(node) success `
handler on_ping(node,payload) = ` node_adx.queue_pong_message(node,payload.nonce) success `
handler on_pong(node, payload) = ` gettime node.ping_delay; gettime node.last_pong; sub node.ping_delay, node.last_ping; set node.next_pong = 0; set node.synching = 1; success `
handler on_inv(node, payload) = ` node_adx.queue_getdata_message(node, payload.hashes) success `
handler on_addr(node, payload) = ` foreach payload.addrs > node_adx.node_log_addr_infos; node_adx.node_add_remote_peers(node,payload.addrs) success `
handler on_tx(node, payload) = ` node_adx.node_add_tx_to_mempool(payload.tx) ? node_adx.check_tx_files(node,payload.tx) endor success `
handler on_mempool(node, payload) = ` node_adx.node_get_mempool_hashes(hash_list) node_adx.queue_inv_message(node,hash_list) success `
handler on_version(node,payload) = `
if(node.entrant = 1)
set node.p2p_addr.port = payload.my_addr.port;
endif
set node.p2p_addr.services = payload.services;
set node.my_addr = payload.their_addr;
set node.user_agent = payload.user_agent;
set node.version = payload.proto_ver;
set node.block_height = payload.last_blk;
node_adx.node_find_peer(node) ? node_adx.node_disconnect(node); error endor
node_adx.node_log_version_infos (node)
node_adx.node_set_bookmark (node.p2p_addr, one);
node_adx.queue_verack_message (node)
node_adx.node_broadcast_addr (node.p2p_addr)
success
`
handler on_block(node, payload) = `
block_adx.set_block_hash(payload.header) : set payload.header.keep_block = 0; success endor
if (node.testing_chain>0)
if (payload.header.prev ! node.last_header_hash)
set payload.header.keep_block = 1;
success
endif
node_adx.node_add_block_header(node, payload.header)
set cur_len = SelfNode.block_height;
add cur_len, SelfNode.bestChainDepth;
sub cur_len, node.testing_chain;
if (node.block_headers* > cur_len)
nodix.truncate_chain_to (node.testing_chain) : success endor
set node.testing_chain = 0 ;
endif
endif
node_adx.node_is_next_block(payload.header) :
node_adx.node_check_chain(node, payload.header) : success endor
endor
set payload.header.signature = payload.signature;
nodix.accept_block(payload.header, payload.txs): log "rejected block" success endor
log "store block"
block_adx.store_block(payload.header, payload.txs) : log "error storing block" success endor
log "store staking"
configuration.staking.pos_kernel.store_blk_staking (payload.header)
configuration.staking.pos_kernel.store_blk_tx_staking (payload.txs)
log "new block added"
block_adx.block_has_pow(payload.header.blkHash) ?
node_adx.node_compute_pow_diff_after (payload.header)
block_adx.get_pow_reward (SelfNode.block_height, block_reward)
set SelfNode.pow_reward = block_reward;
endor
block_adx.block_has_pow(payload.header.blkHash) :
configuration.staking.pos_kernel.compute_last_pos_diff (payload.header, SelfNode.current_pos_diff)
configuration.staking.pos_kernel.stake_get_reward (SelfNode.block_height, block_reward)
set SelfNode.pos_reward = block_reward;
endor
node_adx.add_money_supply (block_reward)
node_adx.node_set_last_block (payload.header)
node_adx.node_del_txs_from_mempool (payload.txs)
node_adx.node_del_btree_from_mempool()
wallet.store_wallet_txs (payload.txs)
node_adx.set_next_check (30)
success
`
proc init_node = `
protocol_adx.init_protocol (configuration)
block_adx.init_blocks (configuration, SelfNode.trustedApps)
node_adx.node_init_self (SelfNode)
loadmod(configuration.staking.pos_kernel)
configuration.staking.pos_kernel.init_pos(configuration.staking)
nodix.init_staking()
node_adx.node_check_block_index (checkNum,LastGood) ?
nodix.truncate_chain_to (LastGood)
endor
node_adx.node_load_block_indexes ()
block_adx.make_genesis_block(configuration.genesis, genesis_blk)
if (SelfNode.block_height = 0)
node_adx.node_set_last_block (genesis_blk)
node_adx.node_compute_pow_diff_after (genesis_blk)
configuration.staking.pos_kernel.store_blk_staking (genesis_blk)
endif
if (SelfNode.block_height > 1)
node_adx.node_load_last_blks()
block_adx.get_pow_reward(SelfNode.lastPOWBlk.height, block_reward)
set SelfNode.pow_reward = block_reward;
configuration.staking.pos_kernel.load_last_pos_blk(SelfNode.lastPOSBlk) :
set SelfNode.lastPOSBlk = SelfNode.last_block;
configuration.staking.pos_kernel.find_last_pos_block(SelfNode.lastPOSBlk)
node_adx.node_store_last_pos_hash (SelfNode.lastPOSBlk)
endor
configuration.staking.pos_kernel.compute_last_pos_diff (SelfNode.lastPOSBlk, SelfNode.current_pos_diff) : set SelfNode.current_pos_diff = configuration.staking.limit; endor
configuration.staking.pos_kernel.stake_get_reward (SelfNode.lastPOSBlk.height, block_reward)
set SelfNode.pos_reward = block_reward;
endif
sethandler SelfNode.emitted_queue{ "cmd=verack" } = on_verack;
sethandler SelfNode.emitted_queue{ "cmd=version" } = on_version;
sethandler SelfNode.emitted_queue{ "cmd=ping" } = on_ping;
sethandler SelfNode.emitted_queue{ "cmd=pong" } = on_pong;
sethandler SelfNode.emitted_queue{ "cmd=inv" } = on_inv;
sethandler SelfNode.emitted_queue{ "cmd=addr" } = on_addr;
sethandler SelfNode.emitted_queue{ "cmd=mempool" } = on_mempool;
sethandler SelfNode.emitted_queue{ "cmd=tx" } = on_tx;
node_adx.node_load_bookmark() :
node_adx.connect_peer_node(configuration.seed_node)
endor
node_adx.set_next_check(0)
success
`