diff --git a/internal/fakechain/fakechain.go b/internal/fakechain/fakechain.go index d24004722..8c0af5d0a 100644 --- a/internal/fakechain/fakechain.go +++ b/internal/fakechain/fakechain.go @@ -140,11 +140,6 @@ func (chain *FakeChain) GetNotaryBalance(acc util.Uint160) *big.Int { panic("TODO") } -// GetPolicer implements Blockchainer interface. -func (chain *FakeChain) GetPolicer() blockchainer.Policer { - return chain -} - // GetBaseExecFee implements Policer interface. func (chain *FakeChain) GetBaseExecFee() int64 { return interop.DefaultBaseExecFee diff --git a/internal/testchain/transaction.go b/internal/testchain/transaction.go index 5797bee08..c4636f08d 100644 --- a/internal/testchain/transaction.go +++ b/internal/testchain/transaction.go @@ -120,7 +120,7 @@ func SignTxCommittee(bc blockchainer.Blockchainer, txs ...*transaction.Transacti func signTxGeneric(bc blockchainer.Blockchainer, sign func(hash.Hashable) []byte, verif []byte, txs ...*transaction.Transaction) { for _, tx := range txs { size := io.GetVarSize(tx) - netFee, sizeDelta := fee.Calculate(bc.GetPolicer().GetBaseExecFee(), verif) + netFee, sizeDelta := fee.Calculate(bc.GetBaseExecFee(), verif) tx.NetworkFee += netFee size += sizeDelta tx.NetworkFee += int64(size) * bc.FeePerByte() diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index 50ceca6f2..71bb5d7d5 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -544,7 +544,7 @@ func signTx(t *testing.T, bc blockchainer.Blockchainer, txs ...*transaction.Tran require.NoError(t, err) for _, tx := range txs { size := io.GetVarSize(tx) - netFee, sizeDelta := fee.Calculate(bc.GetPolicer().GetBaseExecFee(), rawScript) + netFee, sizeDelta := fee.Calculate(bc.GetBaseExecFee(), rawScript) tx.NetworkFee += +netFee size += sizeDelta tx.NetworkFee += int64(size) * bc.FeePerByte() diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index d30ead62c..c15f2ea0c 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -2333,13 +2333,6 @@ func (bc *Blockchain) RegisterPostBlock(f func(blockchainer.Blockchainer, *mempo bc.postBlock = append(bc.postBlock, f) } -// -- start Policer. - -// GetPolicer provides access to policy values via Policer interface. -func (bc *Blockchain) GetPolicer() blockchainer.Policer { - return bc -} - // GetBaseExecFee return execution price for `NOP`. func (bc *Blockchain) GetBaseExecFee() int64 { return bc.contracts.Policy.GetExecFeeFactorInternal(bc.dao) @@ -2357,5 +2350,3 @@ func (bc *Blockchain) GetStoragePrice() int64 { } return bc.contracts.Policy.GetStoragePriceInternal(bc.dao) } - -// -- end Policer. diff --git a/pkg/core/blockchainer/blockchainer.go b/pkg/core/blockchainer/blockchainer.go index 1b12cd9c6..3e75062dc 100644 --- a/pkg/core/blockchainer/blockchainer.go +++ b/pkg/core/blockchainer/blockchainer.go @@ -53,7 +53,6 @@ type Blockchainer interface { GetTokenLastUpdated(acc util.Uint160) (map[int32]uint32, error) GetNotaryContractScriptHash() util.Uint160 GetNotaryBalance(acc util.Uint160) *big.Int - GetPolicer() Policer GetValidators() ([]*keys.PublicKey, error) GetStandByCommittee() keys.PublicKeys GetStandByValidators() keys.PublicKeys @@ -81,4 +80,9 @@ type Blockchainer interface { UnsubscribeFromExecutions(ch chan<- *state.AppExecResult) UnsubscribeFromNotifications(ch chan<- *subscriptions.NotificationEvent) UnsubscribeFromTransactions(ch chan<- *transaction.Transaction) + // Policer. + GetBaseExecFee() int64 + GetMaxVerificationGAS() int64 + GetStoragePrice() int64 + FeePerByte() int64 } diff --git a/pkg/core/blockchainer/policer.go b/pkg/core/blockchainer/policer.go deleted file mode 100644 index 29c3a3ca5..000000000 --- a/pkg/core/blockchainer/policer.go +++ /dev/null @@ -1,9 +0,0 @@ -package blockchainer - -// Policer is an interface that abstracts the implementation of policy methods. -type Policer interface { - GetBaseExecFee() int64 - GetMaxVerificationGAS() int64 - GetStoragePrice() int64 - FeePerByte() int64 -} diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index daa202b94..a22980793 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -63,7 +63,7 @@ func NewContext(trigger trigger.Type, bc blockchainer.Blockchainer, d dao.DAO, dao := d.GetWrapped() if bc != nil && (block == nil || block.Index != 0) { - baseExecFee = bc.GetPolicer().GetBaseExecFee() + baseExecFee = bc.GetBaseExecFee() } return &Context{ Chain: bc, diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index fd473b65b..c72b38779 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -125,7 +125,7 @@ func putWithContext(ic *interop.Context, stc *StorageContext, key []byte, value sizeInc = (len(si)-1)/4 + 1 + len(value) - len(si) } } - if !ic.VM.AddGas(int64(sizeInc) * ic.Chain.GetPolicer().GetStoragePrice()) { + if !ic.VM.AddGas(int64(sizeInc) * ic.Chain.GetStoragePrice()) { return errGasLimitExceeded } return ic.DAO.PutStorageItem(stc.ID, key, value) diff --git a/pkg/core/native/interop.go b/pkg/core/native/interop.go index cf12a419b..077a18aab 100644 --- a/pkg/core/native/interop.go +++ b/pkg/core/native/interop.go @@ -41,8 +41,8 @@ func Call(ic *interop.Context) error { return fmt.Errorf("missing call flags for native %d `%s` operation call: %05b vs %05b", version, m.MD.Name, ic.VM.Context().GetCallFlags(), m.RequiredFlags) } - invokeFee := m.CPUFee*ic.Chain.GetPolicer().GetBaseExecFee() + - m.StorageFee*ic.Chain.GetPolicer().GetStoragePrice() + invokeFee := m.CPUFee*ic.Chain.GetBaseExecFee() + + m.StorageFee*ic.Chain.GetStoragePrice() if !ic.VM.AddGas(invokeFee) { return errors.New("gas limit exceeded") } diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index 3b63cfef0..ced63f251 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -198,7 +198,7 @@ func (m *Management) getNefAndManifestFromItems(ic *interop.Context, args []stac return nil, nil, fmt.Errorf("invalid manifest: %w", err) } - gas := ic.Chain.GetPolicer().GetStoragePrice() * int64(len(nefBytes)+len(manifestBytes)) + gas := ic.Chain.GetStoragePrice() * int64(len(nefBytes)+len(manifestBytes)) if isDeploy { fee := m.GetMinimumDeploymentFee(ic.DAO) if fee > gas { diff --git a/pkg/neotest/basic.go b/pkg/neotest/basic.go index 72d8f9cd0..46ef05c0c 100644 --- a/pkg/neotest/basic.go +++ b/pkg/neotest/basic.go @@ -236,7 +236,7 @@ func addSystemFee(bc blockchainer.Blockchainer, tx *transaction.Transaction, sys } func addNetworkFee(bc blockchainer.Blockchainer, tx *transaction.Transaction, signers ...Signer) { - baseFee := bc.GetPolicer().GetBaseExecFee() + baseFee := bc.GetBaseExecFee() size := io.GetVarSize(tx) for _, sgr := range signers { netFee, sizeDelta := fee.Calculate(baseFee, sgr.Script()) diff --git a/pkg/network/server.go b/pkg/network/server.go index 3eb6e06f7..ddca67d2f 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -1048,7 +1048,7 @@ func (s *Server) verifyAndPoolNotaryRequest(r *payload.P2PNotaryRequest) error { func verifyNotaryRequest(bc blockchainer.Blockchainer, _ *transaction.Transaction, data interface{}) error { r := data.(*payload.P2PNotaryRequest) payer := r.FallbackTransaction.Signers[1].Account - if _, err := bc.VerifyWitness(payer, r, &r.Witness, bc.GetPolicer().GetMaxVerificationGAS()); err != nil { + if _, err := bc.VerifyWitness(payer, r, &r.Witness, bc.GetMaxVerificationGAS()); err != nil { return fmt.Errorf("bad P2PNotaryRequest payload witness: %w", err) } notaryHash := bc.GetNotaryContractScriptHash() diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 76cf975c5..19f596260 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -620,13 +620,13 @@ func (s *Server) calculateNetworkFee(reqParams request.Params) (interface{}, *re } if ef == 0 { - ef = s.chain.GetPolicer().GetBaseExecFee() + ef = s.chain.GetBaseExecFee() } fee, sizeDelta := fee.Calculate(ef, verificationScript) netFee += fee size += sizeDelta } - fee := s.chain.GetPolicer().FeePerByte() + fee := s.chain.FeePerByte() netFee += int64(size) * fee return result.NetworkFee{Value: netFee}, nil } @@ -1698,7 +1698,7 @@ func (s *Server) runScriptInVM(t trigger.Type, script []byte, contractScriptHash if t == trigger.Verification { // We need this special case because witnesses verification is not the simple System.Contract.Call, // and we need to define exactly the amount of gas consumed for a contract witness verification. - gasPolicy := s.chain.GetPolicer().GetMaxVerificationGAS() + gasPolicy := s.chain.GetMaxVerificationGAS() if vm.GasLimit > gasPolicy { vm.GasLimit = gasPolicy } diff --git a/pkg/services/notary/notary.go b/pkg/services/notary/notary.go index 9fd69fe22..a0bc20e0b 100644 --- a/pkg/services/notary/notary.go +++ b/pkg/services/notary/notary.go @@ -227,7 +227,7 @@ func (n *Notary) OnNewRequest(payload *payload.P2PNotaryRequest) { switch r.witnessInfo[i].typ { case Contract: // Need to check even if r.main.Scripts[i].InvocationScript is already filled in. - _, err := n.Config.Chain.VerifyWitness(r.main.Signers[i].Account, r.main, &w, n.Config.Chain.GetPolicer().GetMaxVerificationGAS()) + _, err := n.Config.Chain.VerifyWitness(r.main.Signers[i].Account, r.main, &w, n.Config.Chain.GetMaxVerificationGAS()) if err != nil { continue } diff --git a/pkg/services/oracle/response.go b/pkg/services/oracle/response.go index 2c4be8262..d6525d2f7 100644 --- a/pkg/services/oracle/response.go +++ b/pkg/services/oracle/response.go @@ -115,7 +115,7 @@ func (o *Oracle) CreateResponseTx(gasForResponse int64, vub uint32, resp *transa } tx.NetworkFee += gasConsumed - netFee, sizeDelta := fee.Calculate(o.Chain.GetPolicer().GetBaseExecFee(), tx.Scripts[1].VerificationScript) + netFee, sizeDelta := fee.Calculate(o.Chain.GetBaseExecFee(), tx.Scripts[1].VerificationScript) tx.NetworkFee += netFee size += sizeDelta @@ -139,7 +139,7 @@ func (o *Oracle) testVerify(tx *transaction.Transaction) (int64, bool) { // So make a copy of tx to avoid wrong hash caching. cp := *tx v, finalize := o.Chain.GetTestVM(trigger.Verification, &cp, nil) - v.GasLimit = o.Chain.GetPolicer().GetMaxVerificationGAS() + v.GasLimit = o.Chain.GetMaxVerificationGAS() v.LoadScriptWithHash(o.oracleScript, o.oracleHash, callflag.ReadOnly) v.Context().Jump(o.verifyOffset)