blockchainer: drop Policer interface
We never use it as a proper interface, so it makes no sense keeping it this way.
This commit is contained in:
parent
fcbb0aacc2
commit
c942402957
15 changed files with 20 additions and 39 deletions
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue