mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-22 19:19:09 +00:00
parent
c88ebaede9
commit
36d486a664
12 changed files with 45 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
||||||
ProtocolConfiguration:
|
ProtocolConfiguration:
|
||||||
Magic: 5195086
|
Magic: 5195086
|
||||||
MaxTraceableBlocks: 2102400
|
MaxTraceableBlocks: 2102400
|
||||||
|
InitialGASSupply: 52000000
|
||||||
SecondsPerBlock: 15
|
SecondsPerBlock: 15
|
||||||
MemPoolSize: 50000
|
MemPoolSize: 50000
|
||||||
StandbyCommittee:
|
StandbyCommittee:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
ProtocolConfiguration:
|
ProtocolConfiguration:
|
||||||
Magic: 844378958
|
Magic: 844378958
|
||||||
MaxTraceableBlocks: 2102400
|
MaxTraceableBlocks: 2102400
|
||||||
|
InitialGASSupply: 52000000
|
||||||
SecondsPerBlock: 15
|
SecondsPerBlock: 15
|
||||||
MemPoolSize: 50000
|
MemPoolSize: 50000
|
||||||
StandbyCommittee:
|
StandbyCommittee:
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
|
@ -30,7 +31,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestContractHashes(t *testing.T) {
|
func TestContractHashes(t *testing.T) {
|
||||||
cs := native.NewContracts(true, map[string][]uint32{})
|
cfg := config.ProtocolConfiguration{P2PSigExtensions: true}
|
||||||
|
cs := native.NewContracts(cfg)
|
||||||
require.Equalf(t, []byte(neo.Hash), cs.NEO.Hash.BytesBE(), "%q", string(cs.NEO.Hash.BytesBE()))
|
require.Equalf(t, []byte(neo.Hash), cs.NEO.Hash.BytesBE(), "%q", string(cs.NEO.Hash.BytesBE()))
|
||||||
require.Equalf(t, []byte(gas.Hash), cs.GAS.Hash.BytesBE(), "%q", string(cs.GAS.Hash.BytesBE()))
|
require.Equalf(t, []byte(gas.Hash), cs.GAS.Hash.BytesBE(), "%q", string(cs.GAS.Hash.BytesBE()))
|
||||||
require.Equalf(t, []byte(oracle.Hash), cs.Oracle.Hash.BytesBE(), "%q", string(cs.Oracle.Hash.BytesBE()))
|
require.Equalf(t, []byte(oracle.Hash), cs.Oracle.Hash.BytesBE(), "%q", string(cs.Oracle.Hash.BytesBE()))
|
||||||
|
@ -92,7 +94,8 @@ type nativeTestCase struct {
|
||||||
|
|
||||||
// Here we test that corresponding method does exist, is invoked and correct value is returned.
|
// Here we test that corresponding method does exist, is invoked and correct value is returned.
|
||||||
func TestNativeHelpersCompile(t *testing.T) {
|
func TestNativeHelpersCompile(t *testing.T) {
|
||||||
cs := native.NewContracts(true, map[string][]uint32{})
|
cfg := config.ProtocolConfiguration{P2PSigExtensions: true}
|
||||||
|
cs := native.NewContracts(cfg)
|
||||||
u160 := `interop.Hash160("aaaaaaaaaaaaaaaaaaaa")`
|
u160 := `interop.Hash160("aaaaaaaaaaaaaaaaaaaa")`
|
||||||
u256 := `interop.Hash256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")`
|
u256 := `interop.Hash256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")`
|
||||||
pub := `interop.PublicKey("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")`
|
pub := `interop.PublicKey("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProtocolConfiguration represents the protocol config.
|
// ProtocolConfiguration represents the protocol config.
|
||||||
|
@ -9,6 +10,9 @@ type (
|
||||||
ProtocolConfiguration struct {
|
ProtocolConfiguration struct {
|
||||||
Magic netmode.Magic `yaml:"Magic"`
|
Magic netmode.Magic `yaml:"Magic"`
|
||||||
MemPoolSize int `yaml:"MemPoolSize"`
|
MemPoolSize int `yaml:"MemPoolSize"`
|
||||||
|
|
||||||
|
// InitialGASSupply is the amount of GAS generated in the genesis block.
|
||||||
|
InitialGASSupply fixedn.Fixed8 `yaml:"InitialGASSupply"`
|
||||||
// P2PNotaryRequestPayloadPoolSize specifies the memory pool size for P2PNotaryRequestPayloads.
|
// P2PNotaryRequestPayloadPoolSize specifies the memory pool size for P2PNotaryRequestPayloads.
|
||||||
// It is valid only if P2PSigExtensions are enabled.
|
// It is valid only if P2PSigExtensions are enabled.
|
||||||
P2PNotaryRequestPayloadPoolSize int `yaml:"P2PNotaryRequestPayloadPoolSize"`
|
P2PNotaryRequestPayloadPoolSize int `yaml:"P2PNotaryRequestPayloadPoolSize"`
|
||||||
|
|
|
@ -389,13 +389,14 @@ func TestVerifyBlock(t *testing.T) {
|
||||||
require.True(t, srv.verifyBlock(&neoBlock{Block: *b}))
|
require.True(t, srv.verifyBlock(&neoBlock{Block: *b}))
|
||||||
})
|
})
|
||||||
t.Run("good conflicting tx", func(t *testing.T) {
|
t.Run("good conflicting tx", func(t *testing.T) {
|
||||||
|
initGAS := srv.Chain.GetConfig().InitialGASSupply
|
||||||
tx1 := transaction.New([]byte{byte(opcode.RET)}, 100000)
|
tx1 := transaction.New([]byte{byte(opcode.RET)}, 100000)
|
||||||
tx1.NetworkFee = 20_000_000 * native.GASFactor
|
tx1.NetworkFee = int64(initGAS)/2 + 1
|
||||||
tx1.ValidUntilBlock = 1
|
tx1.ValidUntilBlock = 1
|
||||||
addSender(t, tx1)
|
addSender(t, tx1)
|
||||||
signTx(t, srv.Chain, tx1)
|
signTx(t, srv.Chain, tx1)
|
||||||
tx2 := transaction.New([]byte{byte(opcode.RET)}, 100000)
|
tx2 := transaction.New([]byte{byte(opcode.RET)}, 100000)
|
||||||
tx2.NetworkFee = 20_000_000 * native.GASFactor
|
tx2.NetworkFee = int64(initGAS)/2 + 1
|
||||||
tx2.ValidUntilBlock = 1
|
tx2.ValidUntilBlock = 1
|
||||||
addSender(t, tx2)
|
addSender(t, tx2)
|
||||||
signTx(t, srv.Chain, tx2)
|
signTx(t, srv.Chain, tx2)
|
||||||
|
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
@ -44,6 +45,7 @@ const (
|
||||||
headerBatchCount = 2000
|
headerBatchCount = 2000
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
|
defaultInitialGAS = 52000000_00000000
|
||||||
defaultMemPoolSize = 50000
|
defaultMemPoolSize = 50000
|
||||||
defaultP2PNotaryRequestPayloadPoolSize = 1000
|
defaultP2PNotaryRequestPayloadPoolSize = 1000
|
||||||
defaultMaxBlockSize = 262144
|
defaultMaxBlockSize = 262144
|
||||||
|
@ -165,6 +167,10 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L
|
||||||
return nil, errors.New("empty logger")
|
return nil, errors.New("empty logger")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.InitialGASSupply <= 0 {
|
||||||
|
cfg.InitialGASSupply = fixedn.Fixed8(defaultInitialGAS)
|
||||||
|
log.Info("initial gas supply is not set or wrong, setting default value", zap.String("InitialGASSupply", cfg.InitialGASSupply.String()))
|
||||||
|
}
|
||||||
if cfg.MemPoolSize <= 0 {
|
if cfg.MemPoolSize <= 0 {
|
||||||
cfg.MemPoolSize = defaultMemPoolSize
|
cfg.MemPoolSize = defaultMemPoolSize
|
||||||
log.Info("mempool size is not set or wrong, setting default value", zap.Int("MemPoolSize", cfg.MemPoolSize))
|
log.Info("mempool size is not set or wrong, setting default value", zap.Int("MemPoolSize", cfg.MemPoolSize))
|
||||||
|
@ -216,8 +222,7 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L
|
||||||
events: make(chan bcEvent),
|
events: make(chan bcEvent),
|
||||||
subCh: make(chan interface{}),
|
subCh: make(chan interface{}),
|
||||||
unsubCh: make(chan interface{}),
|
unsubCh: make(chan interface{}),
|
||||||
|
contracts: *native.NewContracts(cfg),
|
||||||
contracts: *native.NewContracts(cfg.P2PSigExtensions, cfg.NativeUpdateHistories),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bc.stateRoot = stateroot.NewModule(bc, bc.log, bc.dao.Store)
|
bc.stateRoot = stateroot.NewModule(bc, bc.log, bc.dao.Store)
|
||||||
|
|
|
@ -1639,7 +1639,7 @@ func TestConfigNativeUpdateHistory(t *testing.T) {
|
||||||
cfgPath := path.Join(prefixPath, fmt.Sprintf("protocol.%s.yml", cfgFileSuffix))
|
cfgPath := path.Join(prefixPath, fmt.Sprintf("protocol.%s.yml", cfgFileSuffix))
|
||||||
cfg, err := config.LoadFile(cfgPath)
|
cfg, err := config.LoadFile(cfgPath)
|
||||||
require.NoError(t, err, fmt.Errorf("failed to load %s", cfgPath))
|
require.NoError(t, err, fmt.Errorf("failed to load %s", cfgPath))
|
||||||
natives := native.NewContracts(cfg.ProtocolConfiguration.P2PSigExtensions, map[string][]uint32{})
|
natives := native.NewContracts(cfg.ProtocolConfiguration)
|
||||||
assert.Equal(t, len(natives.Contracts),
|
assert.Equal(t, len(natives.Contracts),
|
||||||
len(cfg.ProtocolConfiguration.NativeUpdateHistories),
|
len(cfg.ProtocolConfiguration.NativeUpdateHistories),
|
||||||
fmt.Errorf("protocol configuration file %s: extra or missing NativeUpdateHistory in NativeActivations section", cfgPath))
|
fmt.Errorf("protocol configuration file %s: extra or missing NativeUpdateHistory in NativeActivations section", cfgPath))
|
||||||
|
|
|
@ -4,12 +4,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// "C" and "O" can easily be typed by accident.
|
// "C" and "O" can easily be typed by accident.
|
||||||
func TestNamesASCII(t *testing.T) {
|
func TestNamesASCII(t *testing.T) {
|
||||||
cs := NewContracts(true, map[string][]uint32{})
|
cfg := config.ProtocolConfiguration{P2PSigExtensions: true}
|
||||||
|
cs := NewContracts(cfg)
|
||||||
for _, c := range cs.Contracts {
|
for _, c := range cs.Contracts {
|
||||||
require.True(t, isASCII(c.Metadata().Name))
|
require.True(t, isASCII(c.Metadata().Name))
|
||||||
for _, m := range c.Metadata().Methods {
|
for _, m := range c.Metadata().Methods {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package native
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
@ -55,7 +56,7 @@ func (cs *Contracts) ByName(name string) interop.Contract {
|
||||||
|
|
||||||
// NewContracts returns new set of native contracts with new GAS, NEO, Policy, Oracle,
|
// NewContracts returns new set of native contracts with new GAS, NEO, Policy, Oracle,
|
||||||
// Designate and (optional) Notary contracts.
|
// Designate and (optional) Notary contracts.
|
||||||
func NewContracts(p2pSigExtensionsEnabled bool, nativeUpdateHistories map[string][]uint32) *Contracts {
|
func NewContracts(cfg config.ProtocolConfiguration) *Contracts {
|
||||||
cs := new(Contracts)
|
cs := new(Contracts)
|
||||||
|
|
||||||
mgmt := newManagement()
|
mgmt := newManagement()
|
||||||
|
@ -74,7 +75,7 @@ func NewContracts(p2pSigExtensionsEnabled bool, nativeUpdateHistories map[string
|
||||||
cs.Ledger = ledger
|
cs.Ledger = ledger
|
||||||
cs.Contracts = append(cs.Contracts, ledger)
|
cs.Contracts = append(cs.Contracts, ledger)
|
||||||
|
|
||||||
gas := newGAS()
|
gas := newGAS(int64(cfg.InitialGASSupply))
|
||||||
neo := newNEO()
|
neo := newNEO()
|
||||||
neo.GAS = gas
|
neo.GAS = gas
|
||||||
gas.NEO = neo
|
gas.NEO = neo
|
||||||
|
@ -90,7 +91,7 @@ func NewContracts(p2pSigExtensionsEnabled bool, nativeUpdateHistories map[string
|
||||||
cs.Policy = policy
|
cs.Policy = policy
|
||||||
cs.Contracts = append(cs.Contracts, policy)
|
cs.Contracts = append(cs.Contracts, policy)
|
||||||
|
|
||||||
desig := newDesignate(p2pSigExtensionsEnabled)
|
desig := newDesignate(cfg.P2PSigExtensions)
|
||||||
desig.NEO = neo
|
desig.NEO = neo
|
||||||
cs.Designate = desig
|
cs.Designate = desig
|
||||||
cs.Contracts = append(cs.Contracts, desig)
|
cs.Contracts = append(cs.Contracts, desig)
|
||||||
|
@ -102,7 +103,7 @@ func NewContracts(p2pSigExtensionsEnabled bool, nativeUpdateHistories map[string
|
||||||
cs.Oracle = oracle
|
cs.Oracle = oracle
|
||||||
cs.Contracts = append(cs.Contracts, oracle)
|
cs.Contracts = append(cs.Contracts, oracle)
|
||||||
|
|
||||||
if p2pSigExtensionsEnabled {
|
if cfg.P2PSigExtensions {
|
||||||
notary := newNotary()
|
notary := newNotary()
|
||||||
notary.GAS = gas
|
notary.GAS = gas
|
||||||
notary.NEO = neo
|
notary.NEO = neo
|
||||||
|
@ -111,12 +112,13 @@ func NewContracts(p2pSigExtensionsEnabled bool, nativeUpdateHistories map[string
|
||||||
cs.Contracts = append(cs.Contracts, notary)
|
cs.Contracts = append(cs.Contracts, notary)
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultHistory := len(nativeUpdateHistories) == 0
|
setDefaultHistory := len(cfg.NativeUpdateHistories) == 0
|
||||||
for _, c := range cs.Contracts {
|
for _, c := range cs.Contracts {
|
||||||
if setDefaultHistory {
|
var history = []uint32{0}
|
||||||
nativeUpdateHistories[c.Metadata().Name] = []uint32{0}
|
if !setDefaultHistory {
|
||||||
|
history = cfg.NativeUpdateHistories[c.Metadata().Name]
|
||||||
}
|
}
|
||||||
c.Metadata().NativeContract.UpdateHistory = nativeUpdateHistories[c.Metadata().Name]
|
c.Metadata().NativeContract.UpdateHistory = history
|
||||||
}
|
}
|
||||||
return cs
|
return cs
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,17 +21,18 @@ import (
|
||||||
type GAS struct {
|
type GAS struct {
|
||||||
nep17TokenNative
|
nep17TokenNative
|
||||||
NEO *NEO
|
NEO *NEO
|
||||||
|
|
||||||
|
initialSupply int64
|
||||||
}
|
}
|
||||||
|
|
||||||
const gasContractID = -6
|
const gasContractID = -6
|
||||||
|
|
||||||
// GASFactor is a divisor for finding GAS integral value.
|
// GASFactor is a divisor for finding GAS integral value.
|
||||||
const GASFactor = NEOTotalSupply
|
const GASFactor = NEOTotalSupply
|
||||||
const initialGAS = 30000000
|
|
||||||
|
|
||||||
// newGAS returns GAS native contract.
|
// newGAS returns GAS native contract.
|
||||||
func newGAS() *GAS {
|
func newGAS(init int64) *GAS {
|
||||||
g := &GAS{}
|
g := &GAS{initialSupply: init}
|
||||||
defer g.UpdateHash()
|
defer g.UpdateHash()
|
||||||
|
|
||||||
nep17 := newNEP17Native(nativenames.Gas, gasContractID)
|
nep17 := newNEP17Native(nativenames.Gas, gasContractID)
|
||||||
|
@ -109,7 +110,7 @@ func (g *GAS) Initialize(ic *interop.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
g.mint(ic, h, big.NewInt(initialGAS*GASFactor), false)
|
g.mint(ic, h, big.NewInt(g.initialSupply), false)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNativenamesIsValid(t *testing.T) {
|
func TestNativenamesIsValid(t *testing.T) {
|
||||||
// test that all native names has been added to IsValid
|
// test that all native names has been added to IsValid
|
||||||
contracts := NewContracts(true, map[string][]uint32{})
|
cfg := config.ProtocolConfiguration{P2PSigExtensions: true}
|
||||||
|
contracts := NewContracts(cfg)
|
||||||
for _, c := range contracts.Contracts {
|
for _, c := range contracts.Contracts {
|
||||||
require.True(t, nativenames.IsValid(c.Metadata().Name), fmt.Errorf("add %s to nativenames.IsValid(...)", c))
|
require.True(t, nativenames.IsValid(c.Metadata().Name), fmt.Errorf("add %s to nativenames.IsValid(...)", c))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCompatibility(t *testing.T) {
|
func TestCompatibility(t *testing.T) {
|
||||||
cs := native.NewContracts(false, map[string][]uint32{})
|
cs := native.NewContracts(config.ProtocolConfiguration{})
|
||||||
require.Equal(t, cs.Ledger.ID, int32(ledgerContractID))
|
require.Equal(t, cs.Ledger.ID, int32(ledgerContractID))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue