forked from febe19/bazo-miner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstate.go
620 lines (528 loc) · 19.9 KB
/
state.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
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
package miner
import (
"errors"
"fmt"
"github.com/julwil/bazo-miner/crypto"
"github.com/julwil/bazo-miner/p2p"
"github.com/julwil/bazo-miner/protocol"
"github.com/julwil/bazo-miner/storage"
"sort"
"strconv"
"time"
)
//Separate function to reuse mechanism in client implementation
func CheckAndChangeParameters(parameters *Parameters, configTxSlice *[]*protocol.ConfigTx) (change bool) {
for _, tx := range *configTxSlice {
switch tx.Id {
case protocol.FEE_MINIMUM_ID:
if parameterBoundsChecking(protocol.FEE_MINIMUM_ID, tx.Payload) {
parameters.FeeMinimum = tx.Payload
change = true
}
case protocol.BLOCK_SIZE_ID:
if parameterBoundsChecking(protocol.BLOCK_SIZE_ID, tx.Payload) {
parameters.BlockSize = tx.Payload
logger.Printf("BLOCK_SIZE: %v", parameters.BlockSize)
change = true
}
case protocol.BLOCK_REWARD_ID:
if parameterBoundsChecking(protocol.BLOCK_REWARD_ID, tx.Payload) {
parameters.BlockReward = tx.Payload
change = true
}
case protocol.DIFF_INTERVAL_ID:
if parameterBoundsChecking(protocol.DIFF_INTERVAL_ID, tx.Payload) {
parameters.DiffInterval = tx.Payload
logger.Printf("BLOCK_DIFF: %v", parameters.DiffInterval)
change = true
}
case protocol.BLOCK_INTERVAL_ID:
if parameterBoundsChecking(protocol.BLOCK_INTERVAL_ID, tx.Payload) {
parameters.BlockInterval = tx.Payload
logger.Printf("BLOCK_INVTERVAL: %v", parameters.BlockInterval)
change = true
}
case protocol.STAKING_MINIMUM_ID:
if parameterBoundsChecking(protocol.STAKING_MINIMUM_ID, tx.Payload) {
parameters.StakingMinimum = tx.Payload
change = true
//Go through all accounts and remove all validators from the validator sett that no longer fulfill the minimum staking amount
for _, account := range storage.State {
if account.IsStaking && account.Balance < 0+tx.Payload {
account.IsStaking = false
}
}
}
case protocol.WAITING_MINIMUM_ID:
if parameterBoundsChecking(protocol.WAITING_MINIMUM_ID, tx.Payload) {
parameters.WaitingMinimum = tx.Payload
change = true
}
case protocol.ACCEPTANCE_TIME_DIFF_ID:
if parameterBoundsChecking(protocol.ACCEPTANCE_TIME_DIFF_ID, tx.Payload) {
parameters.AcceptedTimeDiff = tx.Payload
change = true
}
case protocol.SLASHING_WINDOW_SIZE_ID:
if parameterBoundsChecking(protocol.SLASHING_WINDOW_SIZE_ID, tx.Payload) {
parameters.SlashingWindowSize = tx.Payload
change = true
}
case protocol.SLASHING_REWARD_ID:
if parameterBoundsChecking(protocol.SLASHING_REWARD_ID, tx.Payload) {
parameters.SlashReward = tx.Payload
change = true
}
}
}
return change
}
//For logging purposes
func getState() (state string) {
for _, acc := range storage.State {
state += fmt.Sprintf("Is root: %v, %v\n", storage.IsRootKey(acc.Hash()), acc)
}
return state
}
func initState() (initialBlock *protocol.Block, err error) {
var allClosedBlocks []*protocol.Block
if p2p.IsBootstrap() {
allClosedBlocks = storage.ReadAllClosedBlocks()
} else {
p2p.LastBlockReq()
var lastBlock *protocol.Block
//Blocking wait
select {
case encodedBlock := <-p2p.BlockReqChan:
lastBlock = lastBlock.Decode(encodedBlock)
//Limit waiting time to BLOCKFETCH_TIMEOUT seconds before aborting.
case <-time.After(BLOCKFETCH_TIMEOUT * time.Second):
return nil, errors.New(fmt.Sprintf("Timeout requesting last block for initial startup..."))
}
storage.WriteClosedBlock(lastBlock)
storage.WriteLastClosedBlock(lastBlock)
if len(allClosedBlocks) > 0 && allClosedBlocks[len(allClosedBlocks)-1].Hash == lastBlock.Hash {
fmt.Printf("Block with height %v already exists", lastBlock.Height)
} else {
allClosedBlocks = append(allClosedBlocks, lastBlock)
}
for {
RETRY:
p2p.BlockReq(lastBlock.PrevHash, lastBlock.PrevHashWithoutTx)
//p2p.BlockReq(lastBlock.PrevHash, lastBlock.PrevHashWithoutTx)
select {
case encodedBlock := <-p2p.BlockReqChan:
lastBlock = lastBlock.Decode(encodedBlock)
//Limit waiting time to BLOCKFETCH_TIMEOUT seconds before aborting.
case <-time.After(BLOCKFETCH_TIMEOUT * time.Second):
if p2p.BlockAlreadyReceived(storage.ReadReceivedBlockStash(), lastBlock.PrevHash) {
for _, block := range storage.ReadReceivedBlockStash() {
if block.Hash == lastBlock.PrevHash {
lastBlock = block
break
}
}
logger.Printf("Block %x received Before", lastBlock.PrevHash[0:8])
break
} else {
logger.Printf("Timed out while requesting %x", lastBlock.PrevHash[0:8])
goto RETRY
}
}
//write aggregated blocks to the 'closedblockswithouttx' bucket. Else to the normal closedblocks bucket.
if lastBlock.Aggregated == true {
storage.WriteClosedBlockWithoutTx(lastBlock)
} else {
storage.WriteClosedBlock(lastBlock)
}
if len(allClosedBlocks) > 0 && allClosedBlocks[len(allClosedBlocks)-1].Hash == lastBlock.Hash {
fmt.Printf("Block with height %v already exists", lastBlock.Height)
} else {
allClosedBlocks = append(allClosedBlocks, lastBlock)
}
//fmt.Println("Last block: ", lastBlock.Height)
if lastBlock.Height == 0 {
break
}
}
}
if len(allClosedBlocks) > 0 {
//Set the last closed block as the initial block
initialBlock = allClosedBlocks[0]
for _, blockToValidate := range allClosedBlocks {
if blockToValidate.Height > initialBlock.Height {
initialBlock = blockToValidate
}
}
} else {
initialBlock = newBlock([32]byte{}, [32]byte{}, [crypto.COMM_PROOF_LENGTH]byte{}, 0)
commitmentProof, err := crypto.SignMessageWithRSAKey(rootCommPrivKey, fmt.Sprint(initialBlock.Height))
if err != nil {
return nil, err
}
copy(initialBlock.CommitmentProof[:], commitmentProof[:])
//Append genesis block to the map and save in storage
allClosedBlocks = append(allClosedBlocks, initialBlock)
storage.WriteLastClosedBlock(initialBlock)
storage.WriteClosedBlock(initialBlock)
}
if !p2p.IsBootstrap() {
allClosedBlocks = InvertBlockArray(allClosedBlocks)
}
//Validate all closed blocks and update state
for _, blockToValidate := range allClosedBlocks {
//Prepare datastructure to fill tx payloads
blockDataMap := make(map[[32]byte]blockData)
//Do not validate the genesis block, since a lot of properties are set to nil
if blockToValidate.Hash != [32]byte{} {
// We need to allocate slice space for the underlying array when we pass them as reference.
accTxs := make([]*protocol.AccTx, blockToValidate.NrAccTx)
fundsTxs := make([]*protocol.FundsTx, blockToValidate.NrFundsTx) // TODO: Duplicate?
configTxs := make([]*protocol.ConfigTx, blockToValidate.NrConfigTx)
stakeTxs := make([]*protocol.StakeTx, blockToValidate.NrStakeTx)
aggTxs := make([]*protocol.AggTx, blockToValidate.NrAggTx)
updateTxs := make([]*protocol.UpdateTx, blockToValidate.NrUpdateTx)
var aggregatedFundsTxs []*protocol.FundsTx // TODO: Duplicate?
err = preValidate(blockToValidate, true)
if err != nil {
return nil, errors.New(fmt.Sprintf("Block (%x) could not be prevalidated: %v\n", blockToValidate.Hash[0:8], err))
}
err = fetchTransactions(
true,
blockToValidate,
&accTxs,
&fundsTxs,
&configTxs,
&stakeTxs,
&aggTxs,
&aggregatedFundsTxs,
&updateTxs,
)
if err != nil {
return nil, errors.New(fmt.Sprintf("Block (%x) could not be prevalidated: %v\n", blockToValidate.Hash[0:8], err))
}
blockDataMap[blockToValidate.Hash] = blockData{
accTxs,
fundsTxs,
configTxs,
stakeTxs,
aggTxs,
aggregatedFundsTxs,
updateTxs,
blockToValidate,
}
err = validateState(blockDataMap[blockToValidate.Hash], true)
if err != nil {
return nil, errors.New(fmt.Sprintf("Block (%x) could not be statevalidated: %v\n", blockToValidate.Hash[0:8], err))
}
postValidate(blockDataMap[blockToValidate.Hash], true)
} else {
blockDataMap[blockToValidate.Hash] = blockData{
nil,
nil,
nil,
nil,
nil,
nil,
nil,
blockToValidate,
}
postValidate(blockDataMap[blockToValidate.Hash], true)
}
logger.Printf("Block validated: %d --> %x", blockToValidate.Height, blockToValidate.Hash[0:8])
}
for _, blockToValidate := range allClosedBlocks {
if blockToValidate.Height > lastBlock.Height {
lastBlock = blockToValidate
}
}
logger.Printf("\n\n%v block(s) validated. Chain good to go.\n------------------------------------------------------------------------\n\n", len(allClosedBlocks))
logger.Printf("Last Block: \n%v\n------------------------------------------------------------------------\n\n", lastBlock)
logger.Printf("Current STATE: \n%v\n------------------------------------------------------------------------\n\n", getState())
return initialBlock, nil
}
func accStateChange(txSlice []*protocol.AccTx) error {
for _, tx := range txSlice {
if tx.Header != 2 {
newAcc := protocol.NewAccount(
tx.PubKey,
tx.Issuer,
0,
false,
[crypto.COMM_KEY_LENGTH]byte{},
tx.Contract,
tx.ContractVariables,
tx.Parameters,
)
newAccHash := newAcc.Hash()
acc, _ := storage.GetAccount(newAccHash)
if acc != nil {
//Shouldn't happen, because this should have been prevented when adding an accTx to the block
return errors.New("Address already exists in the state.")
}
//If acc does not exist, write to state
storage.State[newAccHash] = &newAcc
crypto.ChameleonHashParametersMap[newAccHash] = newAcc.Parameters
if tx.Header == 1 {
//First bit set, given account will be a new root account
//It might be cleaner to move this to the storage package (e.g., storage.Delete(...))
//leave it here for now (not fully convinced yet)
storage.RootKeys[newAccHash] = &newAcc
}
} else if tx.Header == 2 {
accHash := protocol.SerializeHashContent(tx.PubKey)
_, err := storage.GetAccount(accHash)
if err != nil {
return err
}
//Second bit set, delete account from root account
delete(storage.RootKeys, accHash)
}
}
return nil
}
//this method does inititate the state change for aggregated Transactions.
func aggTxStateChange(txSlice []*protocol.FundsTx, initialSetup bool) (err error) {
sort.Sort(ByTxCount(txSlice))
if err := fundsStateChange(txSlice, initialSetup); err != nil {
return err
} else {
return nil
}
}
type ByTxCount []*protocol.FundsTx
func (a ByTxCount) Len() int { return len(a) }
func (a ByTxCount) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByTxCount) Less(i, j int) bool { return a[i].TxCnt <= a[j].TxCnt }
func fundsStateChange(txSlice []*protocol.FundsTx, initialSetup bool) (err error) {
for _, tx := range txSlice {
//If transaction is in closed tx, the state was adjusted already.
if storage.ReadClosedTx(tx.Hash()) != nil && !initialSetup {
continue
}
var rootAcc *protocol.Account
//Check if we have to issue new coins (in case a root account signed the tx)
if rootAcc, err = storage.GetRootAccount(tx.From); err != nil {
return err
}
if rootAcc != nil && rootAcc.Balance+tx.Amount+tx.Fee > MAX_MONEY {
return errors.New("Transaction amount would lead to balance overflow at the receiver (root) account.")
}
//Will not be reached if errors occured
if rootAcc != nil {
rootAcc.Balance += tx.Amount
rootAcc.Balance += tx.Fee
}
var accSender, accReceiver *protocol.Account
accSender, err = storage.GetAccount(tx.From)
accReceiver, err = storage.GetAccount(tx.To)
//Check transaction counter
if !initialSetup && tx.Aggregated == false && tx.TxCnt != accSender.TxCnt {
if tx.TxCnt < accSender.TxCnt {
logger.Printf("Tx %x, already in the state.", tx.Hash())
} else {
err = errors.New(fmt.Sprintf("Sender (%x) txCnt in %x does not match: %v (tx.txCnt) vs. %v (state txCnt).", accSender.Address[0:8], tx.Hash(), tx.TxCnt, accSender.TxCnt))
}
}
//Check sender balance
// "!initialSetup" does allow a "Credit" like behaviour where there is no error, regarding the balance. In the end it should match the wanted state.
if !initialSetup && (tx.Amount+tx.Fee) > accSender.Balance {
err = errors.New(fmt.Sprintf("Sender does not have enough funds for the Funds transaction: Balance = %v, Amount = %v, Fee = %v.", accSender.Balance, tx.Amount, tx.Fee))
}
//After Tx fees, account must still have more than the minimum staking amount
if accSender.IsStaking && ((tx.Fee + protocol.MIN_STAKING_MINIMUM + tx.Amount) > accSender.Balance) {
err = errors.New("Sender is staking and does not have enough funds in order to fulfill the required staking minimum.")
}
//Overflow protection
if !initialSetup && tx.Amount+accReceiver.Balance > MAX_MONEY {
err = errors.New("Transaction amount would lead to balance overflow at the receiver account.")
}
if err != nil {
if rootAcc != nil {
//Rollback root's credits if error occurs
rootAcc.Balance -= tx.Amount
rootAcc.Balance -= tx.Fee
}
return err
}
//We're manipulating pointer, no need to write back
accSender.TxCnt += 1
accSender.Balance -= tx.Amount
accReceiver.Balance += tx.Amount
}
return nil
}
//We accept config slices with unknown id, but don't act on the payload. This is in case we have not updated to a new
//software with corresponding code to act on the configTx id/payload
func configStateChange(configTxSlice []*protocol.ConfigTx, blockHash [32]byte) {
var newParameters Parameters
//Initialize it to state right now (before validating config txs)
newParameters = *activeParameters
if len(configTxSlice) == 0 {
return
}
//Only add a new parameter struct if a relevant system parameter changed
if CheckAndChangeParameters(&newParameters, &configTxSlice) {
newParameters.BlockHash = blockHash
parameterSlice = append(parameterSlice, newParameters)
activeParameters = ¶meterSlice[len(parameterSlice)-1]
logger.Printf("Config parameters changed. New configuration: %v", *activeParameters)
}
}
func stakeStateChange(txSlice []*protocol.StakeTx, height uint32, initialSetup bool) (err error) {
for _, tx := range txSlice {
var accSender *protocol.Account
accSender, err = storage.GetAccount(tx.Account)
//Check staking state
if tx.IsStaking == accSender.IsStaking {
err = errors.New("IsStaking state is already set to " + strconv.FormatBool(accSender.IsStaking) + ".")
}
//Check minimum amount
if !initialSetup && tx.IsStaking && accSender.Balance < tx.Fee+activeParameters.StakingMinimum {
err = errors.New(fmt.Sprintf("Sender wants to stake but does not have enough funds (%v) in order to fulfill the required staking minimum (%v).", accSender.Balance, STAKING_MINIMUM))
}
//Check sender balance
if !initialSetup && tx.Fee > accSender.Balance {
err = errors.New(fmt.Sprintf("Sender (%x) does not have enough funds for the Stake transaction: Balance = %v, Amount = %v, Fee = %v.", accSender.Address[0:8], accSender.Balance, 0, tx.Fee))
}
if err != nil {
return err
}
//We're manipulating pointer, no need to write back
accSender.IsStaking = tx.IsStaking
accSender.CommitmentKey = tx.CommitmentKey
accSender.StakingBlockHeight = height
}
return nil
}
func getFundsTxFromAggTx(AggregatedTxSlice [][32]byte) (fundsTxSlice []*protocol.FundsTx) {
for _, txHash := range AggregatedTxSlice {
trx := storage.ReadOpenTx(txHash)
//Only new funds transactions give a fee... When a transaction is in the closed state, the fee is already collected
if trx != nil {
switch trx.(type) {
case *protocol.FundsTx:
fundsTxSlice = append(fundsTxSlice, trx.(*protocol.FundsTx))
default:
continue
}
}
}
return fundsTxSlice
}
func collectTxFees(accTxSlice []*protocol.AccTx, fundsTxSlice []*protocol.FundsTx, configTxSlice []*protocol.ConfigTx, stakeTxSlice []*protocol.StakeTx, aggTxSlice []*protocol.AggTx, minerHash [32]byte, initialSetup bool) (err error) {
var tmpAccTx []*protocol.AccTx
var tmpFundsTx []*protocol.FundsTx
var tmpConfigTx []*protocol.ConfigTx
var tmpStakeTx []*protocol.StakeTx
//if initialSetup { //TODO DELETE THIS
minerAcc, err := storage.GetAccount(minerHash)
if err != nil {
return err
}
//Get all new Funds Transactions and append them to the fundsTxSlice
for _, tx := range aggTxSlice {
fundsTxSlice = append(fundsTxSlice, getFundsTxFromAggTx(tx.AggregatedTxSlice)...)
}
var senderAcc *protocol.Account
for _, tx := range accTxSlice {
if minerAcc.Balance+tx.Fee > MAX_MONEY {
err = errors.New("Fee amount would lead to balance overflow at the miner account.")
}
if err != nil {
//Rollback of all perviously transferred transaction fees to the protocol's account
collectTxFeesRollback(tmpAccTx, tmpFundsTx, tmpConfigTx, tmpStakeTx, minerHash)
return err
}
//Money gets created from thin air, no need to subtract money from root key
minerAcc.Balance += tx.Fee
tmpAccTx = append(tmpAccTx, tx)
}
//subtract fees from sender (check if that is allowed has already been done in the block validation)
for _, tx := range fundsTxSlice {
//Prevent protocol account from overflowing
if minerAcc.Balance+tx.Fee > MAX_MONEY {
err = errors.New("Fee amount would lead to balance overflow at the miner account.")
}
senderAcc, err = storage.GetAccount(tx.From)
if err != nil {
//Rollback of all perviously transferred transaction fees to the protocol's account
collectTxFeesRollback(tmpAccTx, tmpFundsTx, tmpConfigTx, tmpStakeTx, minerHash)
return err
}
minerAcc.Balance += tx.Fee
senderAcc.Balance -= tx.Fee
tmpFundsTx = append(tmpFundsTx, tx)
}
for _, tx := range configTxSlice {
if minerAcc.Balance+tx.Fee > MAX_MONEY {
err = errors.New("Fee amount would lead to balance overflow at the miner account.")
}
if err != nil {
//Rollback of all perviously transferred transaction fees to the protocol's account
collectTxFeesRollback(tmpAccTx, tmpFundsTx, tmpConfigTx, tmpStakeTx, minerHash)
return err
}
//No need to subtract money because signed by root account
minerAcc.Balance += tx.Fee
tmpConfigTx = append(tmpConfigTx, tx)
}
for _, tx := range stakeTxSlice {
if minerAcc.Balance+tx.Fee > MAX_MONEY {
err = errors.New("Fee amount would lead to balance overflow at the miner account.")
}
senderAcc, err = storage.GetAccount(tx.Account)
if err != nil {
//Rollback of all perviously transferred transaction fees to the protocol's account
collectTxFeesRollback(tmpAccTx, tmpFundsTx, tmpConfigTx, tmpStakeTx, minerHash)
return err
}
senderAcc.Balance -= tx.Fee
minerAcc.Balance += tx.Fee
tmpStakeTx = append(tmpStakeTx, tx)
}
return nil
}
func collectBlockReward(reward uint64, minerHash [32]byte, initialSetup bool) (err error) {
//if initialSetup {
var miner *protocol.Account
miner, err = storage.GetAccount(minerHash)
if !initialSetup && miner.Balance+reward > MAX_MONEY {
err = errors.New("Block reward would lead to balance overflow at the miner account.")
}
if err != nil {
return err
}
miner.Balance += reward
return nil
}
func collectSlashReward(reward uint64, block *protocol.Block) (err error) {
//Check if proof is provided. If proof was incorrect, prevalidation would already have failed.
if block.SlashedAddress != [32]byte{} || block.ConflictingBlockHash1 != [32]byte{} || block.ConflictingBlockHash2 != [32]byte{} || block.ConflictingBlockHashWithoutTx1 != [32]byte{} || block.ConflictingBlockHashWithoutTx2 != [32]byte{} {
var minerAcc, slashedAcc *protocol.Account
minerAcc, err = storage.GetAccount(block.Beneficiary)
slashedAcc, err = storage.GetAccount(block.SlashedAddress)
if minerAcc.Balance+reward > MAX_MONEY {
err = errors.New("Slash reward would lead to balance overflow at the miner account.")
}
if err != nil {
return err
}
//Validator is rewarded with slashing reward for providing a valid slashing proof
minerAcc.Balance += reward
//Slashed account looses the minimum staking amount
slashedAcc.Balance -= activeParameters.StakingMinimum
//Slashed account is being removed from the validator set
slashedAcc.IsStaking = false
}
return nil
}
//No rollback method exists
func updateStakingHeight(block *protocol.Block) error {
acc, err := storage.GetAccount(block.Beneficiary)
if err != nil {
return err
}
acc.StakingBlockHeight = block.Height
return nil
}