Skip to content

Commit

Permalink
Additional tx/voting validation (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
ridenaio authored Aug 21, 2019
1 parent 5d50732 commit 72a54e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions blockchain/offline_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/idena-network/idena-go/common/eventbus"
"github.com/idena-network/idena-go/config"
"github.com/idena-network/idena-go/core/appstate"
"github.com/idena-network/idena-go/core/state"
"github.com/idena-network/idena-go/database"
"github.com/idena-network/idena-go/events"
"github.com/idena-network/idena-go/secstore"
Expand Down Expand Up @@ -95,6 +96,10 @@ func (dt *OfflineDetector) VoteForOffline(block *types.Block) bool {
return false
}

if dt.appState.State.ValidationPeriod() != state.NonePeriod {
return false
}

dt.mutex.Lock()
defer dt.mutex.Unlock()

Expand Down Expand Up @@ -126,6 +131,9 @@ func (dt *OfflineDetector) ValidateBlock(head *types.Header, block *types.Block)
if !dt.appState.ValidatorsCache.IsOnlineIdentity(*addr) {
return errors.New("offline voting works only for online identities")
}
if dt.appState.State.ValidationPeriod() != state.NonePeriod {
return errors.New("block cannot be accepted due to validation ceremony")
}

if offlineCommitSet {
prevAddr := head.OfflineAddr()
Expand All @@ -145,6 +153,9 @@ func (dt *OfflineDetector) ValidateBlock(head *types.Header, block *types.Block)
}

func (dt *OfflineDetector) ProposeOffline(head *types.Header) (*common.Address, types.BlockFlag) {
if dt.appState.State.ValidationPeriod() != state.NonePeriod {
return nil, 0
}
if head.Flags().HasFlag(types.OfflinePropose) {
if dt.verifyOfflineProposing(head.Hash()) {
return head.OfflineAddr(), types.OfflineCommit
Expand Down
6 changes: 6 additions & 0 deletions blockchain/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ func validateOnlineStatusTx(appState *appstate.AppState, tx *types.Transaction,
if err := validateTotalCost(sender, appState, tx); err != nil {
return err
}
if appState.State.ValidationPeriod() >= state.FlipLotteryPeriod {
return LateTx
}
if !appState.ValidatorsCache.Contains(sender) {
return InvalidRecipient
}
Expand All @@ -358,6 +361,9 @@ func validateKillIdentityTx(appState *appstate.AppState, tx *types.Transaction,
if fee.Sign() > 0 && appState.State.GetStakeBalance(sender).Cmp(fee) < 0 {
return InsufficientFunds
}
if appState.State.ValidationPeriod() >= state.FlipLotteryPeriod {
return LateTx
}
if appState.State.GetBalance(sender).Cmp(tx.AmountOrZero()) < 0 {
return InsufficientFunds
}
Expand Down

0 comments on commit 72a54e7

Please sign in to comment.