Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use currency for p2p discovery #812

Merged
merged 2 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions client/knode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"github.com/kowala-tech/kcoin/client/common"
"github.com/kowala-tech/kcoin/client/common/hexutil"
"github.com/kowala-tech/kcoin/client/core"
"github.com/kowala-tech/kcoin/client/knode/currency"
"github.com/kowala-tech/kcoin/client/knode/downloader"
"github.com/kowala-tech/kcoin/client/knode/gasprice"
"github.com/kowala-tech/kcoin/client/params"
)

const KUSD = "kusd"

// DefaultConfig contains default settings for use on the Kowala main net.
var DefaultConfig = Config{
SyncMode: downloader.FastSync,
Expand All @@ -29,7 +28,7 @@ var DefaultConfig = Config{
Blocks: 20,
Percentile: 60,
},
Currency: KUSD,
Currency: currency.KUSD,
}

//go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
Expand Down
3 changes: 3 additions & 0 deletions client/knode/currency/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package currency

const KUSD = "kusd"
4 changes: 2 additions & 2 deletions client/knode/genesis/networks.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package genesis

import "github.com/kowala-tech/kcoin/client/knode"
import "github.com/kowala-tech/kcoin/client/knode/currency"

var Networks = map[string]map[string]Options{
knode.KUSD: {
currency.KUSD: {
MainNetwork: Options{
Network: MainNetwork,
BlockNumber: 0,
Expand Down
11 changes: 7 additions & 4 deletions client/knode/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,15 @@ func (s *Kowala) Start(srvr *p2p.Server) error {
}
}


//fixme: should be removed after develop light client
if srvr.DiscoveryV5 {
chainID := s.chainConfig.ChainID.Int64()
networkID := s.networkID
protocolTopic := discv5.DiscoveryTopic(s.blockchain.Genesis().Hash(), protocol.ProtocolName, protocol.Kcoin1, networkID, chainID)
protocolTopic := discv5.DiscoveryTopic(
s.blockchain.Genesis().Hash(),
protocol.ProtocolName,
protocol.Kcoin1,
s.networkID,
s.chainConfig.ChainID.Int64(),
s.config.Currency)

go func() {
srvr.DiscV5.RegisterTopic(protocolTopic, s.shutdownChan)
Expand Down
10 changes: 8 additions & 2 deletions client/p2p/discv5/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/kowala-tech/kcoin/client/common"
"github.com/kowala-tech/kcoin/client/common/mclock"
cur "github.com/kowala-tech/kcoin/client/knode/currency"
"github.com/kowala-tech/kcoin/client/log"
)

Expand Down Expand Up @@ -392,7 +393,12 @@ func (tq *topicRequestQueue) update(item *topicRequestQueueItem, priority uint64
heap.Fix(tq, item.index)
}

func DiscoveryTopic(genesisHash common.Hash, protocolName string, protocolVersion uint, networkID uint64, chainID int64) Topic {
protocolName = fmt.Sprintf("%s%d-%d.%d", strings.ToUpper(protocolName), protocolVersion, networkID, chainID)
func DiscoveryTopic(genesisHash common.Hash, protocolName string, protocolVersion uint, networkID uint64, chainID int64, currency string) Topic {
if currency == cur.KUSD {
// Don't include currency for kUSD so we don't have to migrate topics. Other currencies will use a different topic
protocolName = fmt.Sprintf("%s%d-%d.%d", strings.ToUpper(protocolName), protocolVersion, networkID, chainID)
} else {
protocolName = fmt.Sprintf("%s%d.%s-%d.%d", strings.ToUpper(protocolName), protocolVersion, currency, networkID, chainID)
}
return Topic(protocolName + "@" + common.Bytes2Hex(genesisHash.Bytes()[0:8]))
}