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 7e88649
Show file tree
Hide file tree
Showing 24 changed files with 1,960 additions and 313 deletions.
236 changes: 236 additions & 0 deletions internal/testchain/testchain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
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"
)

type TestChain struct {
Blockheight uint32
UtilityTokenBalance *big.Int
FeePerByteValue int64
P2PSigExtEnabled bool
DepositBalance *big.Int
DepositExpiration uint32
NotaryScriptHash util.Uint160
MaxNotValidBeforeDelta uint32
}

func (chain TestChain) ApplyPolicyToTxSet([]*transaction.Transaction) []*transaction.Transaction {
panic("TODO")
}
func (chain TestChain) GetConfig() config.ProtocolConfiguration {
panic("TODO")
}
func (chain TestChain) CalculateClaimable(util.Uint160, uint32) (*big.Int, error) {
panic("TODO")
}
func (chain TestChain) FeePerByte() int64 {
if chain.FeePerByteValue != 0 {
return chain.FeePerByteValue
}
panic("TODO")
}
func (chain TestChain) P2PSigExtensionsEnabled() bool {
return chain.P2PSigExtEnabled
}

func (chain TestChain) GetMaxBlockSystemFee() int64 {
panic("TODO")
}

func (chain TestChain) GetMaxBlockSize() uint32 {
panic("TODO")
}

func (chain TestChain) AddHeaders(...*block.Header) error {
panic("TODO")
}
func (chain *TestChain) AddBlock(block *block.Block) error {
if block.Index == chain.Blockheight+1 {
atomic.StoreUint32(&chain.Blockheight, block.Index)
}
return nil
}
func (chain *TestChain) AddStateRoot(r *state.MPTRoot) error {
panic("TODO")
}
func (chain *TestChain) BlockHeight() uint32 {
return atomic.LoadUint32(&chain.Blockheight)
}
func (chain *TestChain) Close() {
panic("TODO")
}
func (chain *TestChain) GetDepositExpiration(acc util.Uint160) uint32 {
if chain.DepositExpiration != 0 {
return chain.DepositExpiration
}
panic("TODO")
}
func (chain *TestChain) GetDepositBalance(acc util.Uint160) *big.Int {
if chain.DepositBalance != nil {
return chain.DepositBalance
}
panic("TODO")
}
func (chain *TestChain) GetMaxNotValidBeforeDelta() uint32 {
if chain.MaxNotValidBeforeDelta != 0 {
return chain.MaxNotValidBeforeDelta
}
panic("TODO")
}
func (chain *TestChain) GetMaxVerificationGAS() int64 {
panic("TODO")
}
func (chain *TestChain) GetPolicer() blockchainer.Policer {
return chain
}
func (chain *TestChain) RegisterPostBlock(f func(blockchainer.Blockchainer, *mempool.Pool, *block.Block)) {
panic("TODO")
}
func (chain TestChain) HeaderHeight() uint32 {
return 0
}
func (chain TestChain) GetAppExecResults(hash util.Uint256, trig trigger.Type) ([]state.AppExecResult, error) {
panic("TODO")
}
func (chain TestChain) GetBlock(hash util.Uint256) (*block.Block, error) {
panic("TODO")
}
func (chain TestChain) GetCommittee() (keys.PublicKeys, error) {
panic("TODO")
}
func (chain TestChain) GetContractState(hash util.Uint160) *state.Contract {
panic("TODO")
}
func (chain TestChain) GetContractScriptHash(id int32) (util.Uint160, error) {
panic("TODO")
}
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")
}
func (chain TestChain) GetHeaderHash(int) util.Uint256 {
return util.Uint256{}
}
func (chain TestChain) GetHeader(hash util.Uint256) (*block.Header, error) {
panic("TODO")
}
func (chain TestChain) GetNextBlockValidators() ([]*keys.PublicKey, error) {
panic("TODO")
}
func (chain TestChain) ForEachNEP17Transfer(util.Uint160, func(*state.NEP17Transfer) (bool, error)) error {
panic("TODO")
}
func (chain TestChain) GetNEP17Balances(util.Uint160) *state.NEP17Balances {
panic("TODO")
}
func (chain TestChain) GetValidators() ([]*keys.PublicKey, error) {
panic("TODO")
}
func (chain TestChain) GetStandByCommittee() keys.PublicKeys {
panic("TODO")
}
func (chain TestChain) GetStandByValidators() keys.PublicKeys {
panic("TODO")
}
func (chain TestChain) GetEnrollments() ([]state.Validator, error) {
panic("TODO")
}
func (chain TestChain) GetStateProof(util.Uint256, []byte) ([][]byte, error) {
panic("TODO")
}
func (chain TestChain) GetStateRoot(height uint32) (*state.MPTRootState, error) {
panic("TODO")
}
func (chain TestChain) GetStorageItem(id int32, key []byte) *state.StorageItem {
panic("TODO")
}
func (chain TestChain) GetTestVM(tx *transaction.Transaction, b *block.Block) *vm.VM {
panic("TODO")
}
func (chain TestChain) GetStorageItems(id int32) (map[string]*state.StorageItem, error) {
panic("TODO")
}
func (chain TestChain) CurrentHeaderHash() util.Uint256 {
return util.Uint256{}
}
func (chain TestChain) CurrentBlockHash() util.Uint256 {
return util.Uint256{}
}
func (chain TestChain) HasBlock(util.Uint256) bool {
return false
}
func (chain TestChain) HasTransaction(util.Uint256) bool {
return false
}
func (chain TestChain) GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) {
panic("TODO")
}
func (chain TestChain) GetMemPool() *mempool.Pool {
panic("TODO")
}
func (chain TestChain) GetGoverningTokenBalance(acc util.Uint160) (*big.Int, uint32) {
panic("TODO")
}
func (chain TestChain) GetUtilityTokenBalance(uint160 util.Uint160) *big.Int {
if chain.UtilityTokenBalance != nil {
return chain.UtilityTokenBalance
}
panic("TODO")
}
func (chain TestChain) PoolTx(*transaction.Transaction, ...*mempool.Pool) error {
panic("TODO")
}
func (chain TestChain) RunWithCurrentState(f func() error) error {
panic("TODO")
}
func (chain TestChain) SubscribeForBlocks(ch chan<- *block.Block) {
panic("TODO")
}
func (chain TestChain) SubscribeForExecutions(ch chan<- *state.AppExecResult) {
panic("TODO")
}
func (chain TestChain) SubscribeForNotifications(ch chan<- *state.NotificationEvent) {
panic("TODO")
}
func (chain TestChain) SubscribeForTransactions(ch chan<- *transaction.Transaction) {
panic("TODO")
}
func (chain TestChain) VerifyTx(*transaction.Transaction) error {
panic("TODO")
}
func (TestChain) VerifyWitness(util.Uint160, crypto.Verifiable, *transaction.Witness, int64) error {
panic("TODO")
}

func (chain TestChain) UnsubscribeFromBlocks(ch chan<- *block.Block) {
panic("TODO")
}
func (chain TestChain) UnsubscribeFromExecutions(ch chan<- *state.AppExecResult) {
panic("TODO")
}
func (chain TestChain) UnsubscribeFromNotifications(ch chan<- *state.NotificationEvent) {
panic("TODO")
}
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
4 changes: 2 additions & 2 deletions pkg/consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func TestVerifyBlock(t *testing.T) {
require.False(t, srv.verifyBlock(&neoBlock{Block: *b}))
})
t.Run("bad big size", func(t *testing.T) {
script := make([]byte, int(srv.Chain.GetMaxBlockSize()))
script := make([]byte, int(srv.Chain.GetPolicer().GetMaxBlockSize()))
script[0] = byte(opcode.RET)
tx := transaction.New(netmode.UnitTestNet, script, 100000)
tx.ValidUntilBlock = 1
Expand All @@ -407,7 +407,7 @@ func TestVerifyBlock(t *testing.T) {
t.Run("bad big sys fee", func(t *testing.T) {
txes := make([]*transaction.Transaction, 2)
for i := range txes {
txes[i] = transaction.New(netmode.UnitTestNet, []byte{byte(opcode.RET)}, srv.Chain.GetMaxBlockSystemFee()/2+1)
txes[i] = transaction.New(netmode.UnitTestNet, []byte{byte(opcode.RET)}, srv.Chain.GetPolicer().GetMaxBlockSystemFee()/2+1)
txes[i].ValidUntilBlock = 1
addSender(t, txes[i])
signTx(t, srv.Chain.FeePerByte(), txes[i])
Expand Down
Loading

0 comments on commit 7e88649

Please sign in to comment.