Skip to content

Commit

Permalink
network: add notary request payload
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaShaleva committed Dec 4, 2020
1 parent b047334 commit 71abc3d
Show file tree
Hide file tree
Showing 24 changed files with 2,074 additions and 313 deletions.
350 changes: 350 additions & 0 deletions internal/testchain/testchain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,350 @@
package testchain

import (
"math/big"
"strings"
"sync/atomic"

"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm"
)

// TestChain is a fake structure which implements Blockchainer interface.
type TestChain struct {
Blockheight uint32
UtilityTokenBalance *big.Int
FeePerByteValue int64
P2PSigExtEnabled bool
DepositBalance *big.Int
DepositExpiration uint32
NotaryScriptHash util.Uint160
MaxNotValidBeforeDelta uint32
}

// ApplyPolicyToTxSet implements Blockchainer interface.
func (chain TestChain) ApplyPolicyToTxSet([]*transaction.Transaction) []*transaction.Transaction {
panic("TODO")
}

// GetConfig implements Blockchainer interface.
func (chain TestChain) GetConfig() config.ProtocolConfiguration {
panic("TODO")
}

// CalculateClaimable implements Blockchainer interface.
func (chain TestChain) CalculateClaimable(util.Uint160, uint32) (*big.Int, error) {
panic("TODO")
}

// FeePerByte implements Blockchainer interface.
func (chain TestChain) FeePerByte() int64 {
if chain.FeePerByteValue != 0 {
return chain.FeePerByteValue
}
panic("TODO")
}

// P2PSigExtensionsEnabled implements Blockchainer interface.
func (chain TestChain) P2PSigExtensionsEnabled() bool {
return chain.P2PSigExtEnabled
}

// GetMaxBlockSystemFee implements Blockchainer interface.
func (chain TestChain) GetMaxBlockSystemFee() int64 {
panic("TODO")
}

// GetMaxBlockSize implements Blockchainer interface.
func (chain TestChain) GetMaxBlockSize() uint32 {
panic("TODO")
}

// AddHeaders implements Blockchainer interface.
func (chain TestChain) AddHeaders(...*block.Header) error {
panic("TODO")
}

// AddBlock implements Blockchainer interface.
func (chain *TestChain) AddBlock(block *block.Block) error {
if block.Index == chain.Blockheight+1 {
atomic.StoreUint32(&chain.Blockheight, block.Index)
}
return nil
}

// AddStateRoot implements Blockchainer interface.
func (chain *TestChain) AddStateRoot(r *state.MPTRoot) error {
panic("TODO")
}

// BlockHeight implements Blockchainer interface.
func (chain *TestChain) BlockHeight() uint32 {
return atomic.LoadUint32(&chain.Blockheight)
}

// Close implements Blockchainer interface.
func (chain *TestChain) Close() {
panic("TODO")
}

// GetDepositExpiration implements Blockchainer interface.
func (chain *TestChain) GetDepositExpiration(acc util.Uint160) uint32 {
if chain.DepositExpiration != 0 {
return chain.DepositExpiration
}
panic("TODO")
}

// GetDepositBalance implements Blockchainer interface.
func (chain *TestChain) GetDepositBalance(acc util.Uint160) *big.Int {
if chain.DepositBalance != nil {
return chain.DepositBalance
}
panic("TODO")
}

// GetMaxNotValidBeforeDelta implements Blockchainer interface.
func (chain *TestChain) GetMaxNotValidBeforeDelta() uint32 {
if chain.MaxNotValidBeforeDelta != 0 {
return chain.MaxNotValidBeforeDelta
}
panic("TODO")
}

// GetMaxVerificationGAS implements Blockchainer interface.
func (chain *TestChain) GetMaxVerificationGAS() int64 {
panic("TODO")
}

// GetPolicer implements Blockchainer interface.
func (chain *TestChain) GetPolicer() blockchainer.Policer {
return chain
}

// RegisterPostBlock implements Blockchainer interface.
func (chain *TestChain) RegisterPostBlock(f func(blockchainer.Blockchainer, *mempool.Pool, *block.Block)) {
panic("TODO")
}

// HeaderHeight implements Blockchainer interface.
func (chain TestChain) HeaderHeight() uint32 {
return 0
}

// GetAppExecResults implements Blockchainer interface.
func (chain TestChain) GetAppExecResults(hash util.Uint256, trig trigger.Type) ([]state.AppExecResult, error) {
panic("TODO")
}

// GetBlock implements Blockchainer interface.
func (chain TestChain) GetBlock(hash util.Uint256) (*block.Block, error) {
panic("TODO")
}

// GetCommittee implements Blockchainer interface.
func (chain TestChain) GetCommittee() (keys.PublicKeys, error) {
panic("TODO")
}

// GetContractState implements Blockchainer interface.
func (chain TestChain) GetContractState(hash util.Uint160) *state.Contract {
panic("TODO")
}

// GetContractScriptHash implements Blockchainer interface.
func (chain TestChain) GetContractScriptHash(id int32) (util.Uint160, error) {
panic("TODO")
}

// GetNativeContractScriptHash implements Blockchainer interface.
func (chain TestChain) GetNativeContractScriptHash(name string) (util.Uint160, error) {
switch strings.ToLower(name) {
case "notary":
if !chain.NotaryScriptHash.Equals(util.Uint160{}) {
return chain.NotaryScriptHash, nil
}
}
panic("TODO")
}

// GetHeaderHash implements Blockchainer interface.
func (chain TestChain) GetHeaderHash(int) util.Uint256 {
return util.Uint256{}
}

// GetHeader implements Blockchainer interface.
func (chain TestChain) GetHeader(hash util.Uint256) (*block.Header, error) {
panic("TODO")
}

// GetNextBlockValidators implements Blockchainer interface.
func (chain TestChain) GetNextBlockValidators() ([]*keys.PublicKey, error) {
panic("TODO")
}

// ForEachNEP17Transfer implements Blockchainer interface.
func (chain TestChain) ForEachNEP17Transfer(util.Uint160, func(*state.NEP17Transfer) (bool, error)) error {
panic("TODO")
}

// GetNEP17Balances implements Blockchainer interface.
func (chain TestChain) GetNEP17Balances(util.Uint160) *state.NEP17Balances {
panic("TODO")
}

// GetValidators implements Blockchainer interface.
func (chain TestChain) GetValidators() ([]*keys.PublicKey, error) {
panic("TODO")
}

// GetStandByCommittee implements Blockchainer interface.
func (chain TestChain) GetStandByCommittee() keys.PublicKeys {
panic("TODO")
}

// GetStandByValidators implements Blockchainer interface.
func (chain TestChain) GetStandByValidators() keys.PublicKeys {
panic("TODO")
}

// GetEnrollments implements Blockchainer interface.
func (chain TestChain) GetEnrollments() ([]state.Validator, error) {
panic("TODO")
}

// GetStateProof implements Blockchainer interface.
func (chain TestChain) GetStateProof(util.Uint256, []byte) ([][]byte, error) {
panic("TODO")
}

// GetStateRoot implements Blockchainer interface.
func (chain TestChain) GetStateRoot(height uint32) (*state.MPTRootState, error) {
panic("TODO")
}

// GetStorageItem implements Blockchainer interface.
func (chain TestChain) GetStorageItem(id int32, key []byte) *state.StorageItem {
panic("TODO")
}

// GetTestVM implements Blockchainer interface.
func (chain TestChain) GetTestVM(tx *transaction.Transaction, b *block.Block) *vm.VM {
panic("TODO")
}

// GetStorageItems implements Blockchainer interface.
func (chain TestChain) GetStorageItems(id int32) (map[string]*state.StorageItem, error) {
panic("TODO")
}

// CurrentHeaderHash implements Blockchainer interface.
func (chain TestChain) CurrentHeaderHash() util.Uint256 {
return util.Uint256{}
}

// CurrentBlockHash implements Blockchainer interface.
func (chain TestChain) CurrentBlockHash() util.Uint256 {
return util.Uint256{}
}

// HasBlock implements Blockchainer interface.
func (chain TestChain) HasBlock(util.Uint256) bool {
return false
}

// HasTransaction implements Blockchainer interface.
func (chain TestChain) HasTransaction(util.Uint256) bool {
return false
}

// GetTransaction implements Blockchainer interface.
func (chain TestChain) GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) {
panic("TODO")
}

// GetMemPool implements Blockchainer interface.
func (chain TestChain) GetMemPool() *mempool.Pool {
panic("TODO")
}

// GetGoverningTokenBalance implements Blockchainer interface.
func (chain TestChain) GetGoverningTokenBalance(acc util.Uint160) (*big.Int, uint32) {
panic("TODO")
}

// GetUtilityTokenBalance implements Blockchainer interface.
func (chain TestChain) GetUtilityTokenBalance(uint160 util.Uint160) *big.Int {
if chain.UtilityTokenBalance != nil {
return chain.UtilityTokenBalance
}
panic("TODO")
}

// PoolTx implements Blockchainer interface.
func (chain TestChain) PoolTx(*transaction.Transaction, ...*mempool.Pool) error {
panic("TODO")
}

// RunWithCurrentState implements Blockchainer interface.
func (chain TestChain) RunWithCurrentState(f func() error) error {
panic("TODO")
}

// SubscribeForBlocks implements Blockchainer interface.
func (chain TestChain) SubscribeForBlocks(ch chan<- *block.Block) {
panic("TODO")
}

// SubscribeForExecutions implements Blockchainer interface.
func (chain TestChain) SubscribeForExecutions(ch chan<- *state.AppExecResult) {
panic("TODO")
}

// SubscribeForNotifications implements Blockchainer interface.
func (chain TestChain) SubscribeForNotifications(ch chan<- *state.NotificationEvent) {
panic("TODO")
}

// SubscribeForTransactions implements Blockchainer interface.
func (chain TestChain) SubscribeForTransactions(ch chan<- *transaction.Transaction) {
panic("TODO")
}

// VerifyTx implements Blockchainer interface.
func (chain TestChain) VerifyTx(*transaction.Transaction) error {
panic("TODO")
}

// VerifyWitness implements Blockchainer interface.
func (TestChain) VerifyWitness(util.Uint160, crypto.Verifiable, *transaction.Witness, int64) error {
panic("TODO")
}

// UnsubscribeFromBlocks implements Blockchainer interface.
func (chain TestChain) UnsubscribeFromBlocks(ch chan<- *block.Block) {
panic("TODO")
}

// UnsubscribeFromExecutions implements Blockchainer interface.
func (chain TestChain) UnsubscribeFromExecutions(ch chan<- *state.AppExecResult) {
panic("TODO")
}

// UnsubscribeFromNotifications implements Blockchainer interface.
func (chain TestChain) UnsubscribeFromNotifications(ch chan<- *state.NotificationEvent) {
panic("TODO")
}

// UnsubscribeFromTransactions implements Blockchainer interface.
func (chain TestChain) UnsubscribeFromTransactions(ch chan<- *transaction.Transaction) {
panic("TODO")
}
5 changes: 4 additions & 1 deletion pkg/config/protocol_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ type (
ProtocolConfiguration struct {
Magic netmode.Magic `yaml:"Magic"`
MemPoolSize int `yaml:"MemPoolSize"`
// P2PNotaryRequestPayloadPoolSize specifies the memory pool size for P2PNotaryRequestPayloads.
// It is valid only if P2PSigExtensions are enabled.
P2PNotaryRequestPayloadPoolSize int `yaml:"P2PNotaryRequestPayloadPoolSize"`
// KeepOnlyLatestState specifies if MPT should only store latest state.
// If true, DB size will be smaller, but older roots won't be accessible.
// This value should remain the same for the same database.
Expand All @@ -17,7 +20,7 @@ type (
RemoveUntraceableBlocks bool `yaml:"RemoveUntraceableBlocks"`
// MaxTraceableBlocks is the length of the chain accessible to smart contracts.
MaxTraceableBlocks uint32 `yaml:"MaxTraceableBlocks"`
// P2PSigExtensions enables additional signature-related transaction attributes
// P2PSigExtensions enables additional signature-related logic.
P2PSigExtensions bool `yaml:"P2PSigExtensions"`
// ReservedAttributes allows to have reserved attributes range for experimental or private purposes.
ReservedAttributes bool `yaml:"ReservedAttributes"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func (s *service) verifyBlock(b block.Block) bool {
s.log.Warn("proposed block has already outdated")
return false
}
maxBlockSize := int(s.Chain.GetMaxBlockSize())
maxBlockSize := int(s.Chain.GetPolicer().GetMaxBlockSize())
size := io.GetVarSize(coreb)
if size > maxBlockSize {
s.log.Warn("proposed block size exceeds policy max block size",
Expand Down Expand Up @@ -454,7 +454,7 @@ func (s *service) verifyBlock(b block.Block) bool {
}
}

maxBlockSysFee := s.Chain.GetMaxBlockSystemFee()
maxBlockSysFee := s.Chain.GetPolicer().GetMaxBlockSystemFee()
if fee > maxBlockSysFee {
s.log.Warn("proposed block system fee exceeds policy max block system fee",
zap.Int("max system fee allowed", int(maxBlockSysFee)),
Expand Down
Loading

0 comments on commit 71abc3d

Please sign in to comment.