nspcc-dev / neo-go

Go Node and SDK for the Neo blockchain
MIT License
123 stars 79 forks source link

How to run local privnet single consensus node? #2874

Closed ixje closed 1 year ago

ixje commented 1 year ago

I've read the consensus document and I think I did all that's needed, but no blocks are produced. What I did is

  1. Set Consensus Enabled in config to true
  2. change wallet and password
  3. use the cli to dump the public key and set that in StandbyCommittee
    ./bin/neo-go wallet dump-keys -w ./examples/my_wallet.json 
    NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB (simple signature contract):
    03844856bae49236e09cee72ecc50848f27165b7e51f637a0fd3f524626747ec6e
  4. Set ValidatorsCount to 1
  5. set my own network magic
  6. Set MinPeers to 1 as per https://github.com/nspcc-dev/neo-go/blob/efbef4254a62a8d6630dd2302cba7ffb424e067e/docs/consensus.md?plain=1#L192-L195

The best I get is this

./bin/neo-go node -p -d
2023-01-12T11:21:30.602+0100    INFO    initial gas supply is not set or wrong, setting default value   {"InitialGASSupply": "52000000"}
2023-01-12T11:21:30.602+0100    INFO    MaxBlockSize is not set or wrong, setting default value {"MaxBlockSize": 262144}
2023-01-12T11:21:30.602+0100    INFO    MaxBlockSystemFee is not set or wrong, setting default value    {"MaxBlockSystemFee": 900000000000}
2023-01-12T11:21:30.602+0100    INFO    MaxTransactionsPerBlock is not set or wrong, using default value    {"MaxTransactionsPerBlock": 512}
2023-01-12T11:21:30.602+0100    INFO    MaxValidUntilBlockIncrement is not set or wrong, using default value    {"MaxValidUntilBlockIncrement": 17280}
2023-01-12T11:21:30.602+0100    INFO    Hardforks are not set, using default value
2023-01-12T11:21:30.603+0100    INFO    restoring blockchain    {"version": "0.2.8"}
2023-01-12T11:21:30.603+0100    INFO    service hasn't started since it's disabled  {"service": "Prometheus"}
2023-01-12T11:21:30.603+0100    INFO    service hasn't started since it's disabled  {"service": "Pprof"}
2023-01-12T11:21:30.603+0100    INFO    ExtensiblePoolSize is not set or wrong, using default value {"ExtensiblePoolSize": 20}
2023-01-12T11:21:30.787+0100    INFO    SessionPoolSize is not set or wrong, setting default value  {"SessionPoolSize": 20}
2023-01-12T11:21:30.787+0100    INFO    MaxWebSocketClients is not set or wrong, setting default value  {"MaxWebSocketClients": 64}
2023-01-12T11:21:30.787+0100    INFO    starting rpc-server {"endpoint": ":20332"}
2023-01-12T11:21:30.787+0100    INFO    node started    {"blockHeight": 0, "headerHeight": 0}

    _   ____________        __________
   / | / / ____/ __ \      / ____/ __ \
  /  |/ / __/ / / / /_____/ / __/ / / /
 / /|  / /___/ /_/ /_____/ /_/ / /_/ /
/_/ |_/_____/\____/      \____/\____/

/NEO-GO:0.100.2-pre-12-g584675ec/

with this config in protocol.privnet.yml

ProtocolConfiguration:
  Magic: 123456789
  MaxTraceableBlocks: 200000
  TimePerBlock: 5s
  MemPoolSize: 50000
  StandbyCommittee:
    - 03844856bae49236e09cee72ecc50848f27165b7e51f637a0fd3f524626747ec6e
  ValidatorsCount: 1
  SeedList:
#    - localhost:20333
#    - localhost:20334
#    - localhost:20335
#    - localhost:20336
  VerifyTransactions: true
  P2PSigExtensions: false
  NativeActivations:
    ContractManagement: [0]
    StdLib: [0]
    CryptoLib: [0]
    LedgerContract: [0]
    NeoToken: [0]
    GasToken: [0]
    PolicyContract: [0]
    RoleManagement: [0]
    OracleContract: [0]

ApplicationConfiguration:
  SkipBlockVerification: false
  # LogPath could be set up in case you need stdout logs to some proper file.
  # LogPath: "./log/neogo.log"
  DBConfiguration:
    Type: "leveldb" #other options: 'inmemory','boltdb'
    # DB type options. Uncomment those you need in case you want to switch DB type.
    LevelDBOptions:
      DataDirectoryPath: "./chains/privnet"
  #    BoltDBOptions:
  #      FilePath: "./chains/privnet.bolt"
  P2P:
    Addresses:
      - ":20333" # in form of "[host]:[port][:announcedPort]"
    DialTimeout: 3s
    ProtoTickInterval: 2s
    PingInterval: 30s
    PingTimeout: 90s
    MaxPeers: 10
    AttemptConnPeers: 5
    MinPeers: 1
  Relay: true
  Consensus:
    Enabled: true
    UnlockWallet:
      Path: "./examples/my_wallet.json"
      Password: "qwerty"
  P2PNotary:
    Enabled: false
    UnlockWallet:
      Path: "/notary_wallet.json"
      Password: "pass"
  RPC:
    Enabled: true
    Addresses:
      - ":20332"
    MaxGasInvoke: 15
    EnableCORSWorkaround: false
    SessionEnabled: true
    SessionExpirationTime: 180 # higher expiration time for manual requests and tests.
    TLSConfig:
        Enabled: false
        Addresses:
          - ":20330"
        CertFile: serv.crt
        KeyFile: serv.key
  Prometheus:
    Enabled: false
    Addresses:
      - ":2112"
  Pprof:
    Enabled: false
    Addresses:
      - ":2113"

I tried adding localhost:20333 to the SeedList if there is some weird thing going on that requires it but all that adds to the above run log is

2023-01-12T11:21:30.921+0100    INFO    new peer connected  {"addr": "127.0.0.1:40682", "peerCount": 1}
2023-01-12T11:21:30.921+0100    INFO    new peer connected  {"addr": "127.0.0.1:20333", "peerCount": 2}
2023-01-12T11:21:30.921+0100    DEBUG   got msg {"addr": "127.0.0.1:40682", "type": "CMDVersion"}
2023-01-12T11:21:30.921+0100    DEBUG   got msg {"addr": "127.0.0.1:20333", "type": "CMDVersion"}
2023-01-12T11:21:30.921+0100    WARN    peer disconnected   {"addr": "127.0.0.1:40682", "error": "identical node id", "peerCount": 1}
2023-01-12T11:21:30.921+0100    WARN    peer disconnected   {"addr": "127.0.0.1:20333", "error": "identical node id", "peerCount": 0}

and then it still "hangs" doing nothing.

What am I missing?

ixje commented 1 year ago

ps: I don't want to use docker. I want the node to be debuggable if needed

roman-khimov commented 1 year ago

Set MinPeers to 1 as per

0, please. You have no peers in this scenario (unless you connect some other node to it).

You may take a look at config/protocol.privnet.docker.single.yml as well, it's a single-node CN that is used for env_single. It can be used without Docker also.

roman-khimov commented 1 year ago

As to why this is important, see https://pkg.go.dev/github.com/nspcc-dev/neo-go/pkg/network#Server.IsInSync

Consensus (and many other services) are started only after node is synchronized (they can work incorrectly otherwise), so your node with MinPeers=1 just doesn't feel confident enough to run dBFT.

ixje commented 1 year ago

Aha that works, thanks. That was totally not obvious to me given that it's in the P2P section I assumed this was only related to something P2P synchronization or connecting to nodes and didn't gave it more thought.

Can I somehow specify a config file? I know I can set the config path, but after that it seems like I can only choose -p, -t or -m

$ ./bin/neo-go help node
NAME:
   neo-go node - start a NeoGo node

USAGE:
   neo-go node [--config-path path] [-d] [-p/-m/-t]

OPTIONS:
   --config-path value  path to directory with configuration files
   --privnet, -p        use private network configuration
   --mainnet, -m        use mainnet network configuration
   --testnet, -t        use testnet network configuration
   --debug, -d          enable debug logging (LOTS of output, overrides configuration)
roman-khimov commented 1 year ago

That's a long-standing bug/feature we have. This mode system expects some particular config file naming pattern relative to config-path and doesn't allow to have xyz.yml. So you have to use protocol.privnet.yml (or mainnet/testnet) for now. At the same time maybe we can finally add --config-file as well, overriding all of this (feel free to add an issue if that will improve your use case).

ixje commented 1 year ago

I think --config-file as suggested is a bit easier to work with. However, it's not like the current way is blocking me. The presence of multiple protocol.privnet.*.yml under /config/ in the repo made me think there might be a way to tell which one to use.