Skip to content
Snippets Groups Projects
Commit 6889228b authored by capossele's avatar capossele
Browse files

:sparkles: adds configuration of the dRNG

parent 392db32e
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,12 @@
"database": {
"directory": "mainnetdb"
},
"drng": {
"instanceId": 1,
"threshold": 3,
"distributedPubKey": "",
"committeeMembers": []
},
"gossip": {
"port": 14666
},
......
package drng
import (
"encoding/base64"
"errors"
"fmt"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/hive.go/crypto/ed25519"
)
var (
// ErrParsingCommitteeMember is returned for an invalid committee member
ErrParsingCommitteeMember = errors.New("cannot parse committee member")
)
func parseCommitteeMembers() (result []ed25519.PublicKey, err error) {
for _, committeeMember := range config.Node.GetStringSlice(CFG_COMMITTEE_MEMBERS) {
if committeeMember == "" {
continue
}
pubKey, err := base64.StdEncoding.DecodeString(committeeMember)
if err != nil {
return nil, fmt.Errorf("%w: invalid public key: %s", ErrParsingCommitteeMember, err)
}
publicKey, err, _ := ed25519.PublicKeyFromBytes(pubKey)
if err != nil {
return nil, err
}
result = append(result, publicKey)
}
return result, nil
}
package drng
import (
flag "github.com/spf13/pflag"
)
const (
CFG_INSTANCE_ID = "drng.instanceId"
CFG_THRESHOLD = "drng.threshold"
CFG_DISTRIBUTED_PUB_KEY = "drng.distributedPubKey"
CFG_COMMITTEE_MEMBERS = "drng.committeeMembers"
)
func init() {
flag.Uint32(CFG_INSTANCE_ID, 1, "instance ID of the drng instance")
flag.Uint32(CFG_THRESHOLD, 3, "BLS threshold of the drng")
flag.String(CFG_DISTRIBUTED_PUB_KEY, "", "distributed public key of the committee (hex encoded)")
flag.StringSlice(CFG_COMMITTEE_MEMBERS, []string{}, "list of committee members of the drng")
}
package drng
import (
"encoding/hex"
"github.com/iotaledger/goshimmer/packages/binary/drng"
"github.com/iotaledger/goshimmer/packages/binary/drng/payload"
"github.com/iotaledger/goshimmer/packages/binary/drng/state"
cbPayload "github.com/iotaledger/goshimmer/packages/binary/drng/subtypes/collectiveBeacon/payload"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/tangle"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/messagelayer"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/logger"
......@@ -23,7 +28,36 @@ var (
func configure(*node.Plugin) {
log = logger.NewLogger(name)
Instance = drng.New()
// parse identities of the committee members
committeeMembers, err := parseCommitteeMembers()
if err != nil {
log.Fatalf("Invalid %s: %s", CFG_COMMITTEE_MEMBERS, err)
}
// parse distributed public key of the committee
var dpk []byte
if str := config.Node.GetString(CFG_DISTRIBUTED_PUB_KEY); str != "" {
bytes, err := hex.DecodeString(str)
if err != nil {
log.Fatalf("Invalid %s: %s", CFG_DISTRIBUTED_PUB_KEY, err)
}
if l := len(bytes); l != cbPayload.PublicKeySize {
log.Fatalf("Invalid %s length: %d, need %d", CFG_DISTRIBUTED_PUB_KEY, l, cbPayload.PublicKeySize)
}
dpk = append(dpk, bytes...)
}
// configure committee
committeeConf := &state.Committee{
InstanceID: config.Node.GetUint32(CFG_INSTANCE_ID),
Threshold: uint8(config.Node.GetUint32(CFG_THRESHOLD)),
DistributedPK: dpk,
Identities: committeeMembers,
}
Instance = drng.New(state.SetCommittee(committeeConf))
configureEvents()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment