mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-01 13:49:13 +00:00
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")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPolicer implements Blockchainer interface.
|
|
||||||
func (chain *FakeChain) GetPolicer() blockchainer.Policer {
|
|
||||||
return chain
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetBaseExecFee implements Policer interface.
|
// GetBaseExecFee implements Policer interface.
|
||||||
func (chain *FakeChain) GetBaseExecFee() int64 {
|
func (chain *FakeChain) GetBaseExecFee() int64 {
|
||||||
return interop.DefaultBaseExecFee
|
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) {
|
func signTxGeneric(bc blockchainer.Blockchainer, sign func(hash.Hashable) []byte, verif []byte, txs ...*transaction.Transaction) {
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
size := io.GetVarSize(tx)
|
size := io.GetVarSize(tx)
|
||||||
netFee, sizeDelta := fee.Calculate(bc.GetPolicer().GetBaseExecFee(), verif)
|
netFee, sizeDelta := fee.Calculate(bc.GetBaseExecFee(), verif)
|
||||||
tx.NetworkFee += netFee
|
tx.NetworkFee += netFee
|
||||||
size += sizeDelta
|
size += sizeDelta
|
||||||
tx.NetworkFee += int64(size) * bc.FeePerByte()
|
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)
|
require.NoError(t, err)
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
size := io.GetVarSize(tx)
|
size := io.GetVarSize(tx)
|
||||||
netFee, sizeDelta := fee.Calculate(bc.GetPolicer().GetBaseExecFee(), rawScript)
|
netFee, sizeDelta := fee.Calculate(bc.GetBaseExecFee(), rawScript)
|
||||||
tx.NetworkFee += +netFee
|
tx.NetworkFee += +netFee
|
||||||
size += sizeDelta
|
size += sizeDelta
|
||||||
tx.NetworkFee += int64(size) * bc.FeePerByte()
|
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)
|
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`.
|
// GetBaseExecFee return execution price for `NOP`.
|
||||||
func (bc *Blockchain) GetBaseExecFee() int64 {
|
func (bc *Blockchain) GetBaseExecFee() int64 {
|
||||||
return bc.contracts.Policy.GetExecFeeFactorInternal(bc.dao)
|
return bc.contracts.Policy.GetExecFeeFactorInternal(bc.dao)
|
||||||
|
@ -2357,5 +2350,3 @@ func (bc *Blockchain) GetStoragePrice() int64 {
|
||||||
}
|
}
|
||||||
return bc.contracts.Policy.GetStoragePriceInternal(bc.dao)
|
return bc.contracts.Policy.GetStoragePriceInternal(bc.dao)
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- end Policer.
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ type Blockchainer interface {
|
||||||
GetTokenLastUpdated(acc util.Uint160) (map[int32]uint32, error)
|
GetTokenLastUpdated(acc util.Uint160) (map[int32]uint32, error)
|
||||||
GetNotaryContractScriptHash() util.Uint160
|
GetNotaryContractScriptHash() util.Uint160
|
||||||
GetNotaryBalance(acc util.Uint160) *big.Int
|
GetNotaryBalance(acc util.Uint160) *big.Int
|
||||||
GetPolicer() Policer
|
|
||||||
GetValidators() ([]*keys.PublicKey, error)
|
GetValidators() ([]*keys.PublicKey, error)
|
||||||
GetStandByCommittee() keys.PublicKeys
|
GetStandByCommittee() keys.PublicKeys
|
||||||
GetStandByValidators() keys.PublicKeys
|
GetStandByValidators() keys.PublicKeys
|
||||||
|
@ -81,4 +80,9 @@ type Blockchainer interface {
|
||||||
UnsubscribeFromExecutions(ch chan<- *state.AppExecResult)
|
UnsubscribeFromExecutions(ch chan<- *state.AppExecResult)
|
||||||
UnsubscribeFromNotifications(ch chan<- *subscriptions.NotificationEvent)
|
UnsubscribeFromNotifications(ch chan<- *subscriptions.NotificationEvent)
|
||||||
UnsubscribeFromTransactions(ch chan<- *transaction.Transaction)
|
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()
|
dao := d.GetWrapped()
|
||||||
|
|
||||||
if bc != nil && (block == nil || block.Index != 0) {
|
if bc != nil && (block == nil || block.Index != 0) {
|
||||||
baseExecFee = bc.GetPolicer().GetBaseExecFee()
|
baseExecFee = bc.GetBaseExecFee()
|
||||||
}
|
}
|
||||||
return &Context{
|
return &Context{
|
||||||
Chain: bc,
|
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)
|
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 errGasLimitExceeded
|
||||||
}
|
}
|
||||||
return ic.DAO.PutStorageItem(stc.ID, key, value)
|
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",
|
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)
|
version, m.MD.Name, ic.VM.Context().GetCallFlags(), m.RequiredFlags)
|
||||||
}
|
}
|
||||||
invokeFee := m.CPUFee*ic.Chain.GetPolicer().GetBaseExecFee() +
|
invokeFee := m.CPUFee*ic.Chain.GetBaseExecFee() +
|
||||||
m.StorageFee*ic.Chain.GetPolicer().GetStoragePrice()
|
m.StorageFee*ic.Chain.GetStoragePrice()
|
||||||
if !ic.VM.AddGas(invokeFee) {
|
if !ic.VM.AddGas(invokeFee) {
|
||||||
return errors.New("gas limit exceeded")
|
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)
|
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 {
|
if isDeploy {
|
||||||
fee := m.GetMinimumDeploymentFee(ic.DAO)
|
fee := m.GetMinimumDeploymentFee(ic.DAO)
|
||||||
if fee > gas {
|
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) {
|
func addNetworkFee(bc blockchainer.Blockchainer, tx *transaction.Transaction, signers ...Signer) {
|
||||||
baseFee := bc.GetPolicer().GetBaseExecFee()
|
baseFee := bc.GetBaseExecFee()
|
||||||
size := io.GetVarSize(tx)
|
size := io.GetVarSize(tx)
|
||||||
for _, sgr := range signers {
|
for _, sgr := range signers {
|
||||||
netFee, sizeDelta := fee.Calculate(baseFee, sgr.Script())
|
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 {
|
func verifyNotaryRequest(bc blockchainer.Blockchainer, _ *transaction.Transaction, data interface{}) error {
|
||||||
r := data.(*payload.P2PNotaryRequest)
|
r := data.(*payload.P2PNotaryRequest)
|
||||||
payer := r.FallbackTransaction.Signers[1].Account
|
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)
|
return fmt.Errorf("bad P2PNotaryRequest payload witness: %w", err)
|
||||||
}
|
}
|
||||||
notaryHash := bc.GetNotaryContractScriptHash()
|
notaryHash := bc.GetNotaryContractScriptHash()
|
||||||
|
|
|
@ -620,13 +620,13 @@ func (s *Server) calculateNetworkFee(reqParams request.Params) (interface{}, *re
|
||||||
}
|
}
|
||||||
|
|
||||||
if ef == 0 {
|
if ef == 0 {
|
||||||
ef = s.chain.GetPolicer().GetBaseExecFee()
|
ef = s.chain.GetBaseExecFee()
|
||||||
}
|
}
|
||||||
fee, sizeDelta := fee.Calculate(ef, verificationScript)
|
fee, sizeDelta := fee.Calculate(ef, verificationScript)
|
||||||
netFee += fee
|
netFee += fee
|
||||||
size += sizeDelta
|
size += sizeDelta
|
||||||
}
|
}
|
||||||
fee := s.chain.GetPolicer().FeePerByte()
|
fee := s.chain.FeePerByte()
|
||||||
netFee += int64(size) * fee
|
netFee += int64(size) * fee
|
||||||
return result.NetworkFee{Value: netFee}, nil
|
return result.NetworkFee{Value: netFee}, nil
|
||||||
}
|
}
|
||||||
|
@ -1698,7 +1698,7 @@ func (s *Server) runScriptInVM(t trigger.Type, script []byte, contractScriptHash
|
||||||
if t == trigger.Verification {
|
if t == trigger.Verification {
|
||||||
// We need this special case because witnesses verification is not the simple System.Contract.Call,
|
// 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.
|
// 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 {
|
if vm.GasLimit > gasPolicy {
|
||||||
vm.GasLimit = gasPolicy
|
vm.GasLimit = gasPolicy
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,7 +227,7 @@ func (n *Notary) OnNewRequest(payload *payload.P2PNotaryRequest) {
|
||||||
switch r.witnessInfo[i].typ {
|
switch r.witnessInfo[i].typ {
|
||||||
case Contract:
|
case Contract:
|
||||||
// Need to check even if r.main.Scripts[i].InvocationScript is already filled in.
|
// 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 {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (o *Oracle) CreateResponseTx(gasForResponse int64, vub uint32, resp *transa
|
||||||
}
|
}
|
||||||
tx.NetworkFee += gasConsumed
|
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
|
tx.NetworkFee += netFee
|
||||||
size += sizeDelta
|
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.
|
// So make a copy of tx to avoid wrong hash caching.
|
||||||
cp := *tx
|
cp := *tx
|
||||||
v, finalize := o.Chain.GetTestVM(trigger.Verification, &cp, nil)
|
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.LoadScriptWithHash(o.oracleScript, o.oracleHash, callflag.ReadOnly)
|
||||||
v.Context().Jump(o.verifyOffset)
|
v.Context().Jump(o.verifyOffset)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue