diff --git a/infrastructure/config/config.go b/infrastructure/config/config.go index 243c76ae2..09dc35925 100644 --- a/infrastructure/config/config.go +++ b/infrastructure/config/config.go @@ -5,9 +5,7 @@ package config import ( - "bufio" "fmt" - "io" "net" "os" "path/filepath" @@ -16,18 +14,15 @@ import ( "strings" "time" - "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" - - "github.com/kaspanet/kaspad/domain/dagconfig" - - "github.com/pkg/errors" - "github.com/btcsuite/go-socks/socks" "github.com/jessevdk/go-flags" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + "github.com/kaspanet/kaspad/domain/dagconfig" "github.com/kaspanet/kaspad/infrastructure/logger" "github.com/kaspanet/kaspad/util" "github.com/kaspanet/kaspad/util/network" "github.com/kaspanet/kaspad/version" + "github.com/pkg/errors" ) const ( @@ -244,9 +239,7 @@ func LoadConfig() (*Config, error) { cfg := &Config{ Flags: cfgFlags, } - if !preCfg.Simnet || preCfg.ConfigFile != - defaultConfigFile { - + if !preCfg.Simnet || preCfg.ConfigFile != defaultConfigFile { if _, err := os.Stat(preCfg.ConfigFile); os.IsNotExist(err) { err := createDefaultConfigFile(preCfg.ConfigFile) if err != nil { @@ -593,13 +586,6 @@ func createDefaultConfigFile(destinationPath string) error { return err } - // We assume sample config file path is same as binary - path, err := filepath.Abs(filepath.Dir(os.Args[0])) - if err != nil { - return err - } - sampleConfigPath := filepath.Join(path, sampleConfigFilename) - dest, err := os.OpenFile(destinationPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { @@ -607,25 +593,7 @@ func createDefaultConfigFile(destinationPath string) error { } defer dest.Close() - src, err := os.Open(sampleConfigPath) - if err != nil { - return err - } - defer src.Close() + _, err = dest.WriteString(sampleConfig) - // We copy every line from the sample config file to the destination - reader := bufio.NewReader(src) - for err != io.EOF { - var line string - line, err = reader.ReadString('\n') - if err != nil && err != io.EOF { - return err - } - - if _, err := dest.WriteString(line); err != nil { - return err - } - } - - return nil + return err } diff --git a/infrastructure/config/config_test.go b/infrastructure/config/config_test.go index 3928e008b..fd205b351 100644 --- a/infrastructure/config/config_test.go +++ b/infrastructure/config/config_test.go @@ -18,7 +18,7 @@ func TestCreateDefaultConfigFile(t *testing.T) { if !ok { t.Fatalf("Failed finding config file path") } - sampleConfigFile := filepath.Join(filepath.Dir(path), "..", "..", "sample-kaspad.conf") + sampleConfigFile := filepath.Join(filepath.Dir(path), "sample-kaspad.conf") // Setup a temporary directory tmpDir, err := ioutil.TempDir("", "kaspad") diff --git a/sample-kaspad.conf b/infrastructure/config/sample-kaspad.conf similarity index 76% rename from sample-kaspad.conf rename to infrastructure/config/sample-kaspad.conf index 708a4324e..b0116484f 100644 --- a/sample-kaspad.conf +++ b/infrastructure/config/sample-kaspad.conf @@ -30,7 +30,7 @@ ; Use Universal Plug and Play (UPnP) to automatically open the listen port ; and obtain the external IP address from supported devices. NOTE: This option -; will have no effect if exernal IP addresses are specified. +; will have no effect if external IP addresses are specified. ; upnp=1 ; Specify the external IP addresses your node is listening on. One address per @@ -83,7 +83,7 @@ ; connect=[fe80::2]:16111 ; Maximum number of inbound and outbound peers. -; maxpeers=125 +; maxinpeers=125 ; Disable banning of misbehaving peers. ; nobanning=1 @@ -142,9 +142,6 @@ ; Disable peer bloom filtering. See BIP0111. ; nopeerbloomfilters=1 -; Add additional checkpoints. Format: ':' -; addcheckpoint=: - ; Add comments to the user agent that is advertised to peers. ; Must not include characters '/', ':', '(' and ')'. ; uacomment= @@ -198,13 +195,6 @@ ; Set the minimum transaction fee to be considered a non-zero fee, ; minrelaytxfee=0.00001 -; Rate-limit free transactions to the value 15 * 1000 bytes per -; minute. -; limitfreerelay=15 - -; Require high priority for relaying free or low-fee transactions. -; norelaypriority=0 - ; Limit orphan transaction pool to 100 transactions. ; maxorphantx=100 @@ -218,22 +208,6 @@ ; rejectnonstd=1 -; ------------------------------------------------------------------------------ -; Optional Indexes -; ------------------------------------------------------------------------------ - -; Build and maintain a full hash-based transaction index which makes all -; transactions available via the getrawtransaction RPC. -; txindex=1 - -; Build and maintain a full address-based transaction index which makes the -; searchrawtransactions RPC available. -; addrindex=1 - -; Delete the entire address index on start up, then exit. -; dropaddrindex=0 - - ; ------------------------------------------------------------------------------ ; Signature Verification Cache ; ------------------------------------------------------------------------------ @@ -242,38 +216,6 @@ ; sigcachemaxsize=50000 -; ------------------------------------------------------------------------------ -; Coin Generation (Mining) Settings - The following options control the -; generation of block templates used by external mining applications through RPC -; calls. -; ------------------------------------------------------------------------------ - -; Add addresses to pay mined blocks to in the block templates generated -; for the getblocktemplate RPC. One address per line. -; miningaddr=kaspa:yourkaspaaddress -; miningaddr=kaspa:yourkaspaaddress2 -; miningaddr=kaspa:yourkaspaaddress3 - -; Specify the minimum block size in bytes to create. By default, only -; transactions which have enough fees or a high enough priority will be included -; in generated block templates. Specifying a minimum block size will instead -; attempt to fill generated block templates up with transactions until it is at -; least the specified number of bytes. -; blockminsize=0 - -; Specify the maximum block size in bytes to create. This value will be limited -; to the consensus limit if it is larger than that value. -; blockmaxsize=750000 - -; Specify the size in bytes of the high-priority/low-fee area when creating a -; block. Transactions which consist of large amounts, old inputs, and small -; sizes have the highest priority. One consequence of this is that as low-fee -; or free transactions age, they raise in priority thereby making them more -; likely to be included in this section of a new block. This value is limited -; by the blackmaxsize option and will be limited as needed. -; blockprioritysize=50000 - - ; ------------------------------------------------------------------------------ ; Debug ; ------------------------------------------------------------------------------ @@ -290,11 +232,3 @@ ; accessed at http://localhost:/debug/pprof once running. ; profile=6061 -; ------------------------------------------------------------------------------ -; Subnetworks -; ------------------------------------------------------------------------------ - -; If subnetwork > 0, than node will request and process only payloads from -; specified subnetwork. And if subnetwork is 0, than payloads of all subnetworks -; are processed. -; subnetwork=0 \ No newline at end of file diff --git a/infrastructure/config/sample_config.go b/infrastructure/config/sample_config.go new file mode 100644 index 000000000..a3c0b0ff6 --- /dev/null +++ b/infrastructure/config/sample_config.go @@ -0,0 +1,238 @@ +package config + +// This should be identical to the content of sample-kaspad.conf +// TODO: Replace with go:embed once go1.16 lands +var sampleConfig = `[Application Options] + +; ------------------------------------------------------------------------------ +; Data settings +; ------------------------------------------------------------------------------ + +; The directory to store data such as the block DAG and peer addresses. The +; block DAG takes several GB, so this location must have a lot of free space. +; The default is ~/.kaspad/data on POSIX OSes, $LOCALAPPDATA/Kaspad/data on Windows, +; ~/Library/Application Support/Kaspad/data on Mac OS, and $home/kaspad/data on +; Plan9. Environment variables are expanded so they may be used. NOTE: Windows +; environment variables are typically %VARIABLE%, but they must be accessed with +; $VARIABLE here. Also, ~ is expanded to $LOCALAPPDATA on Windows. +; datadir=~/.kaspad/data + + +; ------------------------------------------------------------------------------ +; Network settings +; ------------------------------------------------------------------------------ + +; Use testnet. +; testnet=1 + +; Connect via a SOCKS5 proxy. NOTE: Specifying a proxy will disable listening +; for incoming connections unless listen addresses are provided via the 'listen' +; option. +; proxy=127.0.0.1:9050 +; proxyuser= +; proxypass= + +; Use Universal Plug and Play (UPnP) to automatically open the listen port +; and obtain the external IP address from supported devices. NOTE: This option +; will have no effect if external IP addresses are specified. +; upnp=1 + +; Specify the external IP addresses your node is listening on. One address per +; line. kaspad will not contact 3rd-party sites to obtain external ip addresses. +; This means if you are behind NAT, your node will not be able to advertise a +; reachable address unless you specify it here or enable the 'upnp' option (and +; have a supported device). +; externalip=1.2.3.4 +; externalip=2002::1234 + +; ****************************************************************************** +; Summary of 'addpeer' versus 'connect'. +; +; Only one of the following two options, 'addpeer' and 'connect', may be +; specified. Both allow you to specify peers that you want to stay connected +; with, but the behavior is slightly different. By default, kaspad will query DNS +; to find peers to connect to, so unless you have a specific reason such as +; those described below, you probably won't need to modify anything here. +; +; 'addpeer' does not prevent connections to other peers discovered from +; the peers you are connected to and also lets the remote peers know you are +; available so they can notify other peers they can to connect to you. This +; option might be useful if you are having problems finding a node for some +; reason (perhaps due to a firewall). +; +; 'connect', on the other hand, will ONLY connect to the specified peers and +; no others. It also disables listening (unless you explicitly set listen +; addresses via the 'listen' option) and DNS seeding, so you will not be +; advertised as an available peer to the peers you connect to and won't accept +; connections from any other peers. So, the 'connect' option effectively allows +; you to only connect to "trusted" peers. +; ****************************************************************************** + +; Add persistent peers to connect to as desired. One peer per line. +; You may specify each IP address with or without a port. The default port will +; be added automatically if one is not specified here. +; addpeer=192.168.1.1 +; addpeer=10.0.0.2:16111 +; addpeer=fe80::1 +; addpeer=[fe80::2]:16111 + +; Add persistent peers that you ONLY want to connect to as desired. One peer +; per line. You may specify each IP address with or without a port. The +; default port will be added automatically if one is not specified here. +; NOTE: Specifying this option has other side effects as described above in +; the 'addpeer' versus 'connect' summary section. +; connect=192.168.1.1 +; connect=10.0.0.2:16111 +; connect=fe80::1 +; connect=[fe80::2]:16111 + +; Maximum number of inbound and outbound peers. +; maxinpeers=125 + +; Disable banning of misbehaving peers. +; nobanning=1 + +; Maximum allowed ban score before disconnecting and banning misbehaving peers. +; banthreshold=100 + +; How long to ban misbehaving peers. Valid time units are {s, m, h}. +; Minimum 1s. +; banduration=24h +; banduration=11h30m15s + +; Add whitelisted IP networks and IPs. Connected peers whose IP matches a +; whitelist will not have their ban score increased. +; whitelist=127.0.0.1 +; whitelist=::1 +; whitelist=192.168.0.0/24 +; whitelist=fd00::/16 + +; Disable DNS seeding for peers. By default, when kaspad starts, it will use +; DNS to query for available peers to connect with. +; nodnsseed=1 + +; Specify the interfaces to listen on. One listen address per line. +; NOTE: The default port is modified by some options such as 'testnet', so it is +; recommended to not specify a port and allow a proper default to be chosen +; unless you have a specific reason to do otherwise. +; All interfaces on default port (this is the default): +; listen= +; All ipv4 interfaces on default port: +; listen=0.0.0.0 +; All ipv6 interfaces on default port: +; listen=:: +; All interfaces on port 16111: +; listen=:16111 +; All ipv4 interfaces on port 16111: +; listen=0.0.0.0:16111 +; All ipv6 interfaces on port 16111: +; listen=[::]:16111 +; Only ipv4 localhost on port 8333: +; listen=127.0.0.1:8333 +; Only ipv6 localhost on port 8333: +; listen=[::1]:8333 +; Only ipv4 localhost on non-standard port 8336: +; listen=127.0.0.1:8336 +; All interfaces on non-standard port 8336: +; listen=:8336 +; All ipv4 interfaces on non-standard port 8336: +; listen=0.0.0.0:8336 +; All ipv6 interfaces on non-standard port 8336: +; listen=[::]:8336 + +; Disable listening for incoming connections. This will override all listeners. +; nolisten=1 + +; Disable peer bloom filtering. See BIP0111. +; nopeerbloomfilters=1 + +; Add comments to the user agent that is advertised to peers. +; Must not include characters '/', ':', '(' and ')'. +; uacomment= + +; ------------------------------------------------------------------------------ +; RPC server options - The following options control the built-in RPC server +; which is used to control and query information from a running kaspad process. +; ------------------------------------------------------------------------------ + +; Specify the interfaces for the RPC server listen on. One listen address per +; line. NOTE: The default port is modified by some options such as 'testnet', +; so it is recommended to not specify a port and allow a proper default to be +; chosen unless you have a specific reason to do otherwise. By default, the +; RPC server will only listen on localhost for IPv4 and IPv6. +; All interfaces on default port: +; rpclisten= +; All ipv4 interfaces on default port: +; rpclisten=0.0.0.0 +; All ipv6 interfaces on default port: +; rpclisten=:: +; All interfaces on port 16110: +; rpclisten=:16110 +; All ipv4 interfaces on port 16110: +; rpclisten=0.0.0.0:16110 +; All ipv6 interfaces on port 16110: +; rpclisten=[::]:16110 +; Only ipv4 localhost on port 16110: +; rpclisten=127.0.0.1:16110 +; Only ipv6 localhost on port 16110: +; rpclisten=[::1]:16110 +; Only ipv4 localhost on non-standard port 8337: +; rpclisten=127.0.0.1:8337 +; All interfaces on non-standard port 8337: +; rpclisten=:8337 +; All ipv4 interfaces on non-standard port 8337: +; rpclisten=0.0.0.0:8337 +; All ipv6 interfaces on non-standard port 8337: +; rpclisten=[::]:8337 + +; Specify the maximum number of concurrent RPC clients for standard connections. +; rpcmaxclients=10 + +; Use the following setting to disable the RPC server. +; norpc=1 + + +; ------------------------------------------------------------------------------ +; Mempool Settings - The following options +; ------------------------------------------------------------------------------ + +; Set the minimum transaction fee to be considered a non-zero fee, +; minrelaytxfee=0.00001 + +; Limit orphan transaction pool to 100 transactions. +; maxorphantx=100 + +; Do not accept transactions from remote peers. +; blocksonly=1 + +; Relay non-standard transactions regardless of default network settings. +; relaynonstd=1 + +; Reject non-standard transactions regardless of default network settings. +; rejectnonstd=1 + + +; ------------------------------------------------------------------------------ +; Signature Verification Cache +; ------------------------------------------------------------------------------ + +; Limit the signature cache to a max of 50000 entries. +; sigcachemaxsize=50000 + + +; ------------------------------------------------------------------------------ +; Debug +; ------------------------------------------------------------------------------ + +; Debug logging level. +; Valid levels are {trace, debug, info, warn, error, critical} +; You may also specify =,=,... to set +; log level for individual subsystems. Use kaspad --debuglevel=show to list +; available subsystems. +; debuglevel=info + +; The port used to listen for HTTP profile requests. The profile server will +; be disabled if this option is not specified. The profile information can be +; accessed at http://localhost:/debug/pprof once running. +; profile=6061 +`