Repository navigation
Expand file tree
/
Copy pathstructs.h
More file actions
508 lines (432 loc) · 10.6 KB
/
Copy pathstructs.h
File metadata and controls
508 lines (432 loc) · 10.6 KB
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
#pragma once
#include "defines.h"
#include "utils.h"
#include <cstddef>
#include <cstring>
#include "m256i.h"
struct RequestResponseHeader {
private:
uint8_t _size[3];
uint8_t _type;
unsigned int _dejavu;
public:
static constexpr unsigned int max_size = 0xFFFFFF;
inline unsigned int size() const{
if (((*((unsigned int*)_size)) & 0xFFFFFF)==0) return INT32_MAX; // size is never zero, zero means broken packets
return (*((unsigned int*)_size)) & 0xFFFFFF;
}
inline void setSize(unsigned int size) {
_size[0] = (uint8_t)size;
_size[1] = (uint8_t)(size >> 8);
_size[2] = (uint8_t)(size >> 16);
}
inline bool isDejavuZero()
{
return !_dejavu;
}
inline void zeroDejavu()
{
_dejavu = 0;
}
inline void randomizeDejavu()
{
rand32(&_dejavu);
if (!_dejavu)
{
_dejavu = 1;
}
}
void setDejavu(uint32_t dejavu)
{
_dejavu = dejavu;
}
inline uint8_t type() const
{
return _type;
}
inline void setType(const uint8_t type)
{
_type = type;
}
inline uint32_t getDejavu() const
{
return _dejavu;
}
// Return pointer to payload, which is stored behind the header.
// The type() is not checked against the PayloadType!
template <typename PayloadType>
inline PayloadType* getPayload()
{
return reinterpret_cast<PayloadType*>(this + 1);
}
// Check if the payload size is as expected.
inline bool checkPayloadSize(unsigned int expected_payload_size) const
{
return size() == expected_payload_size + sizeof(RequestResponseHeader);
}
// Check if the payload size is in the expected range.
inline bool checkPayloadSizeMinMax(unsigned int min_payload_size, unsigned int max_payload_size) const
{
return min_payload_size + sizeof(RequestResponseHeader) <= size() && size() <= max_payload_size + sizeof(RequestResponseHeader);
}
// Get size of the payload (without checking validity of overall size).
inline unsigned int getPayloadSize() const
{
return this->size() - sizeof(RequestResponseHeader);
}
};
typedef struct
{
unsigned char sourcePublicKey[32];
unsigned char destinationPublicKey[32];
long long amount;
unsigned int tick;
unsigned short inputType;
unsigned short inputSize;
} Transaction;
typedef struct
{
unsigned short tickDuration;
unsigned short epoch;
unsigned int tick;
unsigned short numberOfAlignedVotes;
unsigned short numberOfMisalignedVotes;
unsigned int initialTick;
} CurrentTickInfo;
struct BootstrapInfo
{
unsigned short epoch;
unsigned short padding;
unsigned int initialTick;
m256i identity;
uint8_t signature[64];
} ;
struct TickData
{
unsigned short computorIndex;
unsigned short epoch;
unsigned int tick;
unsigned short millisecond;
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned char day;
unsigned char month;
unsigned char year;
m256i timelock;
m256i transactionDigests[NUMBER_OF_TRANSACTIONS_PER_TICK];
long long contractFees[NUMBER_OF_TRANSACTIONS_PER_TICK];
unsigned char signature[SIGNATURE_SIZE];
static constexpr unsigned char type()
{
return 8;
}
};
// ---- Data Structures to be Stored ----
struct TickVote
{
unsigned short computorIndex;
unsigned short epoch;
unsigned int tick;
unsigned short millisecond;
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned char day;
unsigned char month;
unsigned char year;
unsigned int prevResourceTestingDigest;
unsigned int saltedResourceTestingDigest;
unsigned int prevTransactionBodyDigest;
unsigned int saltedTransactionBodyDigest;
m256i prevSpectrumDigest;
m256i prevUniverseDigest;
m256i prevComputerDigest;
m256i saltedSpectrumDigest;
m256i saltedUniverseDigest;
m256i saltedComputerDigest;
m256i transactionDigest;
m256i expectedNextTickTransactionDigest;
unsigned char signature[SIGNATURE_SIZE];
static constexpr unsigned char type()
{
return 3;
}
};
struct FullTickStruct
{
TickData td;
TickVote tv[676];
};
typedef struct
{
unsigned int tick;
enum {
type = 16,
};
} RequestTickData;
typedef struct
{
unsigned int tick;
unsigned char voteFlags[(NUMBER_OF_COMPUTORS + 7) / 8];
enum {
type = 14,
};
} RequestedQuorumTick;
typedef struct
{
unsigned int tick;
unsigned char flag[NUMBER_OF_TRANSACTIONS_PER_TICK / 8];
enum {
type = 29,
};
} RequestedTickTransactions;
typedef struct
{
uint8_t sig[SIGNATURE_SIZE];
} SignatureStruct;
typedef struct
{
char hash[60];
} TxhashStruct;
typedef struct
{
std::vector<uint8_t> vecU8;
} extraDataStruct;
struct RequestLog // Fetches log
{
unsigned long long passcode[4];
unsigned long long fromid;
unsigned long long toid;
static constexpr unsigned char type()
{
return 44;
}
};
struct RequestLogIdRange // Fetches logId range
{
unsigned long long passcode[4];
unsigned int tick;
unsigned int txId;
static constexpr unsigned char type()
{
return 48;
}
};
struct ResponseLogIdRange // Fetches logId range
{
long long fromLogId;
long long length;
static constexpr unsigned char type()
{
return 49;
}
};
// Request logid ranges of all txs from a tick
struct RequestAllLogIdRangesFromTick
{
unsigned long long passcode[4];
unsigned int tick;
static constexpr unsigned char type()
{
return 50;
}
};
#define LOG_TX_NUMBER_OF_SPECIAL_EVENT 5
#define LOG_TX_PER_TICK (NUMBER_OF_TRANSACTIONS_PER_TICK + LOG_TX_NUMBER_OF_SPECIAL_EVENT)// +5 special events
// Response logid ranges of all txs from a tick
struct ResponseAllLogIdRangesFromTick
{
long long fromLogId[LOG_TX_PER_TICK];
long long length[LOG_TX_PER_TICK];
static constexpr unsigned char type()
{
return 51;
}
};
struct RespondLog // Returns buffered log; clears the buffer; make sure you fetch log quickly enough, if the buffer is overflown log stops being written into it till the node restart
{
// Variable-size log;
static constexpr unsigned char type()
{
return 45;
}
};
// Request logid ranges of all txs from a tick
struct RequestPruningPageFiles
{
unsigned long long passcode[4];
unsigned long long fromLogId;
unsigned long long toLogId;
static constexpr unsigned char type()
{
return 56;
}
};
// Response 0 if success, otherwise error code will be returned
struct ResponsePruningPageFiles
{
long long success;
static constexpr unsigned char type()
{
return 57;
}
};
// Request logid ranges of all txs from a tick
struct RequestLogStateDigest
{
unsigned long long passcode[4];
unsigned int requestedTick;
static constexpr unsigned char type()
{
return 58;
}
};
// Response 0 if success, otherwise error code will be returned
struct ResponseLogStateDigest
{
unsigned char digest[32];
static constexpr unsigned char type()
{
return 59;
}
};
/*STRUCT FOR LOGGING*/
/*
* STRUCTS FOR LOGGING
*/
struct QuTransfer
{
m256i sourcePublicKey;
m256i destinationPublicKey;
long long amount;
};
#pragma pack(push,1)
struct AssetIssuance
{
m256i issuerPublicKey;
long long numberOfShares;
long long managingContractIndex;
char name[7];
char numberOfDecimalPlaces;
char unitOfMeasurement[7];
};
struct AssetOwnershipChange
{
m256i sourcePublicKey;
m256i destinationPublicKey;
m256i issuerPublicKey;
long long numberOfShares;
long long managingContractIndex;
char name[7];
char numberOfDecimalPlaces;
char unitOfMeasurement[7];
};
struct AssetPossessionChange
{
m256i sourcePublicKey;
m256i destinationPublicKey;
m256i issuerPublicKey;
long long numberOfShares;
long long managingContractIndex;
char name[7];
char numberOfDecimalPlaces;
char unitOfMeasurement[7];
};
struct AssetOwnershipManagingContractChange
{
m256i ownershipPublicKey;
m256i issuerPublicKey;
unsigned int sourceContractIndex;
unsigned int destinationContractIndex;
long long numberOfShares;
char assetName[7];
};
struct AssetPossessionManagingContractChange
{
m256i possessionPublicKey;
m256i ownershipPublicKey;
m256i issuerPublicKey;
unsigned int sourceContractIndex;
unsigned int destinationContractIndex;
long long numberOfShares;
char assetName[7];
};
struct Burning
{
m256i sourcePublicKey;
long long amount;
unsigned int contractIndexBurnedFor;
};
struct Computors
{
// TODO: Padding
unsigned short epoch;
m256i publicKeys[NUMBER_OF_COMPUTORS];
unsigned char signature[SIGNATURE_SIZE];
};
static_assert(sizeof(Computors) == 2 + 32 * NUMBER_OF_COMPUTORS + SIGNATURE_SIZE, "Something is wrong with the struct size.");
#pragma pack(pop)
// list of structs that bob uses to communicate logging events
// custom request in bob => request a signature from trusted entities about logging [startLogId, endLogId]
struct RequestLogEventSignature
{
uint32_t tick;
uint32_t chunkid;
long long startLogId;
long long endLogId;
static constexpr unsigned char type()
{
return 144;
}
};
struct ResponseLogSignature
{
m256i identity;
uint32_t tick;
uint32_t chunkid;
long long startLogId, endLogId;
// dynamic size after this, signature is sign(K12(everything before sig))
// last 64 bytes is signature
static constexpr unsigned char type()
{
return 145;
}
};
// ask for signature of the log range
struct RequestLogRangeSignature
{
uint32_t tick;
static constexpr unsigned char type()
{
return 146;
}
};
struct ResponseLogRangeSignature
{
ResponseAllLogIdRangesFromTick lr;
m256i identity;
uint8_t signature[64];
static constexpr unsigned char type()
{
return 147;
}
};
// for query smart contract
struct RequestContractFunction // Invokes contract function
{
unsigned int contractIndex;
unsigned short inputType;
unsigned short inputSize;
// Variable-size input
enum {
type = 42,
};
};
struct RespondContractFunction // Returns result of contract function invocation
{
// Variable-size output; the size must be 0 if the invocation has failed for whatever reason (e.g. no a function registered for [inputType], or the function has timed out)
enum {
type = 43,
};
};