Skip to content

Commit

Permalink
Added checks to make sure we are not pushing negative balances after …
Browse files Browse the repository at this point in the history
…a certain height.
  • Loading branch information
ThePiachu committed Jun 21, 2017
1 parent bfba36c commit aea2098
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion state/factoidstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,19 @@ func (fs *FactoidState) UpdateECTransaction(rt bool, trans interfaces.IECBlockEn
case entryCreditBlock.ECIDChainCommit:
t := trans.(*entryCreditBlock.CommitChain)
v := fs.State.GetE(rt, t.ECPubKey.Fixed()) - int64(t.Credits)
if fs.DBHeight > 93719 && v < 0 {
return fmt.Errorf("Not enough ECs to cover a commit")
}
fs.State.PutE(rt, t.ECPubKey.Fixed(), v)
fs.State.NumTransactions++
fs.State.Replay.IsTSValid(constants.INTERNAL_REPLAY, t.GetSigHash(), t.GetTimestamp())
fs.State.Replay.IsTSValid(constants.NETWORK_REPLAY, t.GetSigHash(), t.GetTimestamp())
case entryCreditBlock.ECIDEntryCommit:
t := trans.(*entryCreditBlock.CommitEntry)
v := fs.State.GetE(rt, t.ECPubKey.Fixed()) - int64(t.Credits)
if fs.DBHeight > 93719 && v < 0 {
return fmt.Errorf("Not enough ECs to cover a commit")
}
fs.State.PutE(rt, t.ECPubKey.Fixed(), v)
fs.State.NumTransactions++
fs.State.Replay.IsTSValid(constants.INTERNAL_REPLAY, t.GetSigHash(), t.GetTimestamp())
Expand All @@ -317,7 +323,11 @@ func (fs *FactoidState) UpdateTransaction(rt bool, trans interfaces.ITransaction
for _, input := range trans.GetInputs() {
adr := input.GetAddress().Fixed()
oldv := fs.State.GetF(rt, adr)
fs.State.PutF(rt, adr, oldv-int64(input.GetAmount()))
v := oldv - int64(input.GetAmount())
if v < 0 {
return fmt.Errorf("Not enough factoids to cover a transaction")
}
fs.State.PutF(rt, adr, v)
}
for _, output := range trans.GetOutputs() {
adr := output.GetAddress().Fixed()
Expand Down

0 comments on commit aea2098

Please sign in to comment.