Skip to content

Commit

Permalink
Use hard-coded sample config instead of assumed path (#1466)
Browse files Browse the repository at this point in the history
* Use hard-coded sample config instead of assumed path

* Fix bad path to sample-kaspad.conf in TestCreateDefaultConfigFile

Co-authored-by: Elichai Turkel <[email protected]>
  • Loading branch information
svarogg and elichai authored Feb 1, 2021
1 parent 12c438d commit d5a3a96
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 107 deletions.
44 changes: 6 additions & 38 deletions infrastructure/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
package config

import (
"bufio"
"fmt"
"io"
"net"
"os"
"path/filepath"
Expand All @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -593,39 +586,14 @@ 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 {
return err
}
defer dest.Close()

src, err := os.Open(sampleConfigPath)
if err != nil {
return err
}
defer src.Close()

// 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
}
}
_, err = dest.WriteString(sampleConfig)

return nil
return err
}
2 changes: 1 addition & 1 deletion infrastructure/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
70 changes: 2 additions & 68 deletions sample-kaspad.conf → infrastructure/config/sample-kaspad.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -142,9 +142,6 @@
; Disable peer bloom filtering. See BIP0111.
; nopeerbloomfilters=1

; Add additional checkpoints. Format: '<height>:<hash>'
; addcheckpoint=<height>:<hash>

; Add comments to the user agent that is advertised to peers.
; Must not include characters '/', ':', '(' and ')'.
; uacomment=
Expand Down Expand Up @@ -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

Expand All @@ -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
; ------------------------------------------------------------------------------
Expand All @@ -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
; ------------------------------------------------------------------------------
Expand All @@ -290,11 +232,3 @@
; accessed at http://localhost:<profileport>/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
Loading

0 comments on commit d5a3a96

Please sign in to comment.