From 0cbd7ed461ac3c3846a3641c12c9d63f1d6d70d7 Mon Sep 17 00:00:00 2001 From: sidenaio Date: Thu, 1 Apr 2021 01:30:18 +0500 Subject: [PATCH 1/3] Disable finish voting --- api/contract_api.go | 5 +++++ blockchain/blockchain.go | 7 +++++++ vm/embedded/oraclevoting.go | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/api/contract_api.go b/api/contract_api.go index 49ea209d..f5283d75 100644 --- a/api/contract_api.go +++ b/api/contract_api.go @@ -12,6 +12,7 @@ import ( "github.com/idena-network/idena-go/deferredtx" "github.com/idena-network/idena-go/subscriptions" "github.com/idena-network/idena-go/vm" + "github.com/idena-network/idena-go/vm/embedded" "github.com/idena-network/idena-go/vm/env" "github.com/idena-network/idena-go/vm/helpers" "github.com/pkg/errors" @@ -316,6 +317,10 @@ func (api *ContractApi) Deploy(ctx context.Context, args DeployArgs) (common.Has } func (api *ContractApi) Call(ctx context.Context, args CallArgs) (common.Hash, error) { + if args.Method == embedded.FinishVotingMethod { + return common.Hash{}, errors.New("finishVoting is temporary disabled") + } + tx, err := api.buildCallContractTx(args) if err != nil { return common.Hash{}, err diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 6b07dd54..8498a043 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -32,6 +32,7 @@ import ( "github.com/idena-network/idena-go/stats/collector" "github.com/idena-network/idena-go/subscriptions" "github.com/idena-network/idena-go/vm" + "github.com/idena-network/idena-go/vm/embedded" cid2 "github.com/ipfs/go-cid" "github.com/pkg/errors" "github.com/shopspring/decimal" @@ -1483,6 +1484,12 @@ func (chain *Blockchain) filterTxs(appState *appstate.AppState, txs []*types.Tra if err := validation.ValidateTx(appState, tx, minFeePerGas, validation.InBlockTx); err != nil { continue } + if tx.Type == types.CallContract { + attachment := attachments.ParseCallContractAttachment(tx) + if attachment!=nil && attachment.Method == embedded.FinishVotingMethod { + continue + } + } if f, r, err := chain.ApplyTxOnState(appState, vm, tx, nil); err == nil { gas := uint64(fee.CalculateGas(tx)) if r != nil { diff --git a/vm/embedded/oraclevoting.go b/vm/embedded/oraclevoting.go index fc511a9d..882eae41 100644 --- a/vm/embedded/oraclevoting.go +++ b/vm/embedded/oraclevoting.go @@ -38,6 +38,7 @@ func NewOracleVotingContract2(ctx env.CallContext, e env.Env, statsCollector col env.NewMap([]byte("allVotes"), e, ctx), } } +const FinishVotingMethod = "finishVoting" func (f *OracleVoting2) Call(method string, args ...[]byte) error { switch method { @@ -47,7 +48,7 @@ func (f *OracleVoting2) Call(method string, args ...[]byte) error { return f.sendVoteProof(args...) case "sendVote": return f.sendVote(args...) - case "finishVoting": + case FinishVotingMethod: return f.finishVoting(args...) case "prolongVoting": return f.prolongVoting(args...) From db1af77e7c2cd00aa5d07d07ac9de302d3e37c9a Mon Sep 17 00:00:00 2001 From: sidenaio Date: Thu, 1 Apr 2021 01:37:20 +0500 Subject: [PATCH 2/3] Disable finishVoting in txpool --- blockchain/blockchain.go | 6 ------ core/mempool/txpool.go | 9 +++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 8498a043..37ceac01 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -1484,12 +1484,6 @@ func (chain *Blockchain) filterTxs(appState *appstate.AppState, txs []*types.Tra if err := validation.ValidateTx(appState, tx, minFeePerGas, validation.InBlockTx); err != nil { continue } - if tx.Type == types.CallContract { - attachment := attachments.ParseCallContractAttachment(tx) - if attachment!=nil && attachment.Method == embedded.FinishVotingMethod { - continue - } - } if f, r, err := chain.ApplyTxOnState(appState, vm, tx, nil); err == nil { gas := uint64(fee.CalculateGas(tx)) if r != nil { diff --git a/core/mempool/txpool.go b/core/mempool/txpool.go index c96d6c87..034a3f49 100644 --- a/core/mempool/txpool.go +++ b/core/mempool/txpool.go @@ -2,6 +2,7 @@ package mempool import ( "github.com/deckarep/golang-set" + "github.com/idena-network/idena-go/blockchain/attachments" "github.com/idena-network/idena-go/blockchain/fee" "github.com/idena-network/idena-go/blockchain/types" "github.com/idena-network/idena-go/blockchain/validation" @@ -12,6 +13,7 @@ import ( "github.com/idena-network/idena-go/events" "github.com/idena-network/idena-go/log" "github.com/idena-network/idena-go/stats/collector" + "github.com/idena-network/idena-go/vm/embedded" "github.com/pkg/errors" "sort" "sync" @@ -216,6 +218,13 @@ func (pool *TxPool) Add(tx *types.Transaction) error { sender, _ := types.Sender(tx) + if tx.Type == types.CallContract { + attachment := attachments.ParseCallContractAttachment(tx) + if attachment != nil && attachment.Method == embedded.FinishVotingMethod { + return errors.New("finishVoting is temporary disabled") + } + } + if pool.isSyncing && sender != pool.coinbase { pool.addDeferredTx(tx) From 4dbb45a5494a29b82040b991b663a5851054948d Mon Sep 17 00:00:00 2001 From: sidenaio Date: Thu, 1 Apr 2021 01:42:34 +0500 Subject: [PATCH 3/3] Fix build --- blockchain/blockchain.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 37ceac01..c5641e42 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -32,7 +32,6 @@ import ( "github.com/idena-network/idena-go/stats/collector" "github.com/idena-network/idena-go/subscriptions" "github.com/idena-network/idena-go/vm" - "github.com/idena-network/idena-go/vm/embedded" cid2 "github.com/ipfs/go-cid" "github.com/pkg/errors" "github.com/shopspring/decimal" @@ -1235,10 +1234,10 @@ func (chain *Blockchain) applyDelegationSwitch(appState *appstate.AppState, bloc for idx := range delegations { delegation := delegations[idx] if delegation.Delegatee.IsEmpty() { - delegatee :=appState.State.Delegatee(delegation.Delegator) + delegatee := appState.State.Delegatee(delegation.Delegator) appState.IdentityState.RemoveDelegatee(delegation.Delegator) appState.State.RemoveDelegatee(delegation.Delegator) - if delegatee!=nil { + if delegatee != nil { undelegations = append(undelegations, &state.Delegation{Delegator: delegation.Delegator, Delegatee: *delegatee}) } } else { @@ -1256,7 +1255,7 @@ func (chain *Blockchain) applyDelegationSwitch(appState *appstate.AppState, bloc return undelegations } -func (chain *Blockchain) switchPoolsToOffline(appState *appstate.AppState, undelegations []*state.Delegation, block *types.Block) { +func (chain *Blockchain) switchPoolsToOffline(appState *appstate.AppState, undelegations []*state.Delegation, block *types.Block) { if !block.Header.Flags().HasFlag(types.IdentityUpdate) { return }