2018-03-25 10:45:54 +00:00
|
|
|
package config
|
2018-03-15 20:45:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2019-09-10 14:22:21 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/storage"
|
2019-02-20 17:39:32 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
2019-10-29 17:51:17 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/network/metrics"
|
2019-02-20 17:39:32 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
2018-03-15 20:45:37 +00:00
|
|
|
"github.com/go-yaml/yaml"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
userAgentFormat = "/NEO-GO:%s/"
|
2018-03-25 10:45:54 +00:00
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// ModeMainNet contains magic code used in the NEO main official network.
|
2019-09-09 08:23:27 +00:00
|
|
|
ModeMainNet NetMode = 0x00746e41 // 7630401
|
2019-09-03 14:51:37 +00:00
|
|
|
// ModeTestNet contains magic code used in the NEO testing network.
|
2019-09-09 08:23:27 +00:00
|
|
|
ModeTestNet NetMode = 0x74746e41 // 1953787457
|
2019-09-03 14:51:37 +00:00
|
|
|
// ModePrivNet contains magic code usually used for NEO private networks.
|
2019-09-09 08:23:27 +00:00
|
|
|
ModePrivNet NetMode = 56753 // docker privnet
|
2019-09-03 14:51:37 +00:00
|
|
|
// ModeUnitTestNet is a stub magic code used for testing purposes.
|
2019-01-22 12:14:52 +00:00
|
|
|
ModeUnitTestNet NetMode = 0
|
2018-03-15 20:45:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Version the version of the node, set at build time.
|
|
|
|
Version string
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Config top level struct representing the config
|
|
|
|
// for the node.
|
|
|
|
Config struct {
|
|
|
|
ProtocolConfiguration ProtocolConfiguration `yaml:"ProtocolConfiguration"`
|
|
|
|
ApplicationConfiguration ApplicationConfiguration `yaml:"ApplicationConfiguration"`
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:01:10 +00:00
|
|
|
// ProtocolConfiguration represents the protocol config.
|
2018-03-15 20:45:37 +00:00
|
|
|
ProtocolConfiguration struct {
|
|
|
|
Magic NetMode `yaml:"Magic"`
|
|
|
|
AddressVersion int64 `yaml:"AddressVersion"`
|
Implement rpc server method: sendrawtransaction (#174)
* Added new config attributes: 'SecondsPerBlock','LowPriorityThreshold'
* Added new files:
* Added new method: CompareTo
* Fixed empty Slice case
* Added new methods: LessThan, GreaterThan, Equal, CompareTo
* Added new method: InputIntersection
* Added MaxTransactionSize, GroupOutputByAssetID
* Added ned method: ScriptHash
* Added new method: IsDoubleSpend
* Refactor blockchainer, Added Feer interface, Verify and GetMemPool method
* 1) Added MemPool
2) Added new methods to satisfy the blockchainer interface: IsLowPriority, Verify, GetMemPool
* Added new methods: RelayTxn, RelayDirectly
* Fixed tests
* Implemented RPC server method sendrawtransaction
* Refactor getrawtransaction, sendrawtransaction in separate methods
* Moved 'secondsPerBlock' to config file
* Implemented Kim suggestions:
1) Fixed data race issues
2) refactor Verify method
3) Get rid of unused InputIntersection method due to refactoring Verify method
4) Fixed bug in https://github.com/CityOfZion/neo-go/pull/174#discussion_r264108135
5) minor simplications of the code
* Fixed minor issues related to
1) space
2) getter methods do not need pointer on the receiver
3) error message
4) refactoring CompareTo method in uint256.go
* Fixed small issues
* Use sync.RWMutex instead of sync.Mutex
* Refined (R)Lock/(R)Unlock
* return error instead of bool in Verify methods
2019-03-20 12:30:05 +00:00
|
|
|
SecondsPerBlock int `yaml:"SecondsPerBlock"`
|
|
|
|
LowPriorityThreshold float64 `yaml:"LowPriorityThreshold"`
|
2018-03-15 20:45:37 +00:00
|
|
|
MaxTransactionsPerBlock int64 `yaml:"MaxTransactionsPerBlock"`
|
|
|
|
StandbyValidators []string `yaml:"StandbyValidators"`
|
|
|
|
SeedList []string `yaml:"SeedList"`
|
|
|
|
SystemFee SystemFee `yaml:"SystemFee"`
|
2019-10-11 14:46:47 +00:00
|
|
|
// Whether to verify received blocks.
|
|
|
|
VerifyBlocks bool `yaml:"VerifyBlocks"`
|
|
|
|
// Whether to verify transactions in received blocks.
|
|
|
|
VerifyTransactions bool `yaml:"VerifyTransactions"`
|
2018-03-15 20:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SystemFee fees related to system.
|
|
|
|
SystemFee struct {
|
|
|
|
EnrollmentTransaction int64 `yaml:"EnrollmentTransaction"`
|
|
|
|
IssueTransaction int64 `yaml:"IssueTransaction"`
|
|
|
|
PublishTransaction int64 `yaml:"PublishTransaction"`
|
|
|
|
RegisterTransaction int64 `yaml:"RegisterTransaction"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ApplicationConfiguration config specific to the node.
|
|
|
|
ApplicationConfiguration struct {
|
2019-10-29 17:51:17 +00:00
|
|
|
DBConfiguration storage.DBConfiguration `yaml:"DBConfiguration"`
|
|
|
|
NodePort uint16 `yaml:"NodePort"`
|
|
|
|
Relay bool `yaml:"Relay"`
|
|
|
|
DialTimeout time.Duration `yaml:"DialTimeout"`
|
|
|
|
ProtoTickInterval time.Duration `yaml:"ProtoTickInterval"`
|
|
|
|
MaxPeers int `yaml:"MaxPeers"`
|
2019-11-06 12:17:20 +00:00
|
|
|
AttemptConnPeers int `yaml:"AttemptConnPeers"`
|
2019-10-31 12:04:28 +00:00
|
|
|
MinPeers int `yaml:"MinPeers"`
|
2019-10-29 17:51:17 +00:00
|
|
|
Monitoring metrics.PrometheusConfig `yaml:"Monitoring"`
|
2019-11-01 10:23:46 +00:00
|
|
|
RPC RPCConfig `yaml:"RPC"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// RPCConfig is an RPC service configuration information (to be moved to the rpc package, see #423).
|
|
|
|
RPCConfig struct {
|
|
|
|
Enabled bool `yaml:"Enabled"`
|
|
|
|
EnableCORSWorkaround bool `yaml:"EnableCORSWorkaround"`
|
|
|
|
Address string `yaml:"Address"`
|
|
|
|
Port uint16 `yaml:"Port"`
|
2018-03-15 20:45:37 +00:00
|
|
|
}
|
2018-03-25 10:45:54 +00:00
|
|
|
|
|
|
|
// NetMode describes the mode the blockchain will operate on.
|
|
|
|
NetMode uint32
|
2018-03-15 20:45:37 +00:00
|
|
|
)
|
|
|
|
|
2018-03-25 10:45:54 +00:00
|
|
|
// String implements the stringer interface.
|
|
|
|
func (n NetMode) String() string {
|
|
|
|
switch n {
|
|
|
|
case ModePrivNet:
|
|
|
|
return "privnet"
|
|
|
|
case ModeTestNet:
|
|
|
|
return "testnet"
|
|
|
|
case ModeMainNet:
|
|
|
|
return "mainnet"
|
2019-01-22 12:14:52 +00:00
|
|
|
case ModeUnitTestNet:
|
|
|
|
return "unit_testnet"
|
2018-03-25 10:45:54 +00:00
|
|
|
default:
|
|
|
|
return "net unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 20:45:37 +00:00
|
|
|
// GenerateUserAgent creates user agent string based on build time environment.
|
|
|
|
func (c Config) GenerateUserAgent() string {
|
|
|
|
return fmt.Sprintf(userAgentFormat, Version)
|
|
|
|
}
|
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// Load attempts to load the config from the given
|
|
|
|
// path for the given netMode.
|
2018-03-25 10:45:54 +00:00
|
|
|
func Load(path string, netMode NetMode) (Config, error) {
|
2018-03-15 20:45:37 +00:00
|
|
|
configPath := fmt.Sprintf("%s/protocol.%s.yml", path, netMode)
|
|
|
|
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
|
|
|
return Config{}, errors.Wrap(err, "Unable to load config")
|
|
|
|
}
|
|
|
|
|
|
|
|
configData, err := ioutil.ReadFile(configPath)
|
|
|
|
if err != nil {
|
|
|
|
return Config{}, errors.Wrap(err, "Unable to read config")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := Config{
|
|
|
|
ProtocolConfiguration: ProtocolConfiguration{
|
|
|
|
SystemFee: SystemFee{},
|
|
|
|
},
|
|
|
|
ApplicationConfiguration: ApplicationConfiguration{},
|
|
|
|
}
|
|
|
|
|
2019-02-09 15:53:58 +00:00
|
|
|
err = yaml.Unmarshal(configData, &config)
|
2018-03-15 20:45:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return Config{}, errors.Wrap(err, "Problem unmarshaling config json data")
|
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
2019-02-20 17:39:32 +00:00
|
|
|
|
|
|
|
// TryGetValue returns the system fee base on transaction type.
|
|
|
|
func (s SystemFee) TryGetValue(txType transaction.TXType) util.Fixed8 {
|
|
|
|
switch txType {
|
|
|
|
case transaction.EnrollmentType:
|
2019-08-23 12:41:22 +00:00
|
|
|
return util.Fixed8FromInt64(s.EnrollmentTransaction)
|
2019-02-20 17:39:32 +00:00
|
|
|
case transaction.IssueType:
|
2019-08-23 12:41:22 +00:00
|
|
|
return util.Fixed8FromInt64(s.IssueTransaction)
|
2019-02-20 17:39:32 +00:00
|
|
|
case transaction.PublishType:
|
2019-08-23 12:41:22 +00:00
|
|
|
return util.Fixed8FromInt64(s.PublishTransaction)
|
2019-02-20 17:39:32 +00:00
|
|
|
case transaction.RegisterType:
|
2019-08-23 12:41:22 +00:00
|
|
|
return util.Fixed8FromInt64(s.RegisterTransaction)
|
2019-02-20 17:39:32 +00:00
|
|
|
default:
|
2019-08-23 12:41:22 +00:00
|
|
|
return util.Fixed8FromInt64(0)
|
2019-02-20 17:39:32 +00:00
|
|
|
}
|
|
|
|
}
|