omnilaboratory / obd

OmniBOLT daemon, a golang implementation of OmniBOLT spec, the smart assets lightning network.
MIT License
213 stars 21 forks source link

Node randomness #23

Closed johng closed 3 years ago

neocarmack commented 3 years ago

lightclient/p2p_util.go

func generatePrivateKey() (crypto.PrivKey, error) {
    if privateKey == nil {
        nodeId := httpGetNodeIdFromTracker()
        if nodeId == 0 {
            return nil, errors.New("fail to get nodeId from tracker")
        }
        r := rand.New(rand.NewSource(int64(8080 + nodeId)))

        prvKey, _, err := crypto.GenerateECDSAKeyPair(r)
        if err != nil {
            log.Println(err)

The private key is only for generating a constant node peer id, not for wallet. We/Users don't want to get variant node id each time their nodes get online. So the logic of this peice of code is to get a constant node id.

johng commented 3 years ago

The issue I was facing is that two instances starting at the same time on the same machine (different trackers) would generate the same nodeId which would break the p2p communication.

neocarmack commented 3 years ago

yes, you are right. Currently the tracker network is not fully decentralized, so that if two nodes connect to different trackers, it may cause conflicts.

But if your nodes connect to a same tracker, it will be ok. We are updating this part of work ( since several days gao). Node id is generated independent of trackers, and nodes located in one machine will definitly have different ids.

I reopened this PR. After we finish this part of work, i will re-assess this again.