Skip to content

Commit 148fbfa

Browse files
authored
Merge pull request #1531 from 0chain/feature/split-key-option
Feature: add separate split key option
2 parents 5e76c29 + cd3007d commit 148fbfa

File tree

9 files changed

+70
-26
lines changed

9 files changed

+70
-26
lines changed

code/go/0chain.net/blobber/flags.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,32 @@ import (
66
)
77

88
var (
9-
deploymentMode int
10-
keysFile string
11-
keysFileRaw string
12-
mountPoint string
13-
metadataDB string
14-
logDir string
15-
httpPort int
16-
hostname string
17-
configDir string
18-
grpcPort int
19-
httpsPort int
20-
httpsKeyFile string
21-
httpsCertFile string
22-
hostUrl string
9+
deploymentMode int
10+
keysFile string
11+
keysFilePublicKey string
12+
keysFilePrivateKey string
13+
keysFileClientKey string
14+
keysFileIsSplit bool
15+
mountPoint string
16+
metadataDB string
17+
logDir string
18+
httpPort int
19+
hostname string
20+
configDir string
21+
grpcPort int
22+
httpsPort int
23+
httpsKeyFile string
24+
httpsCertFile string
25+
hostUrl string
2326
)
2427

2528
func init() {
2629
flag.IntVar(&deploymentMode, "deployment_mode", 2, "deployment mode: 0=dev,1=test, 2=mainnet")
2730
flag.StringVar(&keysFile, "keys_file", "", "keys_file")
28-
flag.StringVar(&keysFileRaw, "keys_file_raw", "", "keys_file_raw")
31+
flag.StringVar(&keysFilePublicKey, "keys_file_public_key", "", "keys_file_public_key")
32+
flag.StringVar(&keysFilePrivateKey, "keys_file_private_key", "", "keys_file_private_key")
33+
flag.StringVar(&keysFileClientKey, "keys_file_client_key", "", "keys_file_client_key")
34+
flag.BoolVar(&keysFileIsSplit, "keys_file_is_split", false, "keys_file_is_split")
2935
flag.StringVar(&mountPoint, "files_dir", "", "Mounted partition where all files will be stored")
3036
flag.StringVar(&metadataDB, "db_dir", "", "db_dir")
3137
flag.StringVar(&logDir, "log_dir", "", "log_dir")

code/go/0chain.net/blobber/node.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ import (
1414
"go.uber.org/zap"
1515
)
1616

17-
var publicKey, privateKey string
17+
var clientKey, publicKey, privateKey string
1818

1919
func setupNode() error {
2020
fmt.Println("> setup blobber")
2121

2222
var err error
2323

24-
if keysFileRaw != "" {
25-
err = readKeysFromString(&keysFileRaw)
24+
if keysFilePrivateKey != "" || keysFilePublicKey != "" {
25+
privateKey = keysFilePrivateKey
26+
publicKey = keysFilePublicKey
27+
28+
if keysFileIsSplit {
29+
clientKey = keysFileClientKey
30+
}
2631

2732
fmt.Println("using blobber keys from local string")
2833
} else {
@@ -38,7 +43,8 @@ func setupNode() error {
3843
}
3944
}
4045

41-
node.Self.SetKeys(publicKey, privateKey)
46+
node.Self.SetKeys(clientKey, publicKey, privateKey, keysFileIsSplit)
47+
4248
if node.Self.ID == "" {
4349
return errors.New("node definition for self node doesn't exist")
4450
} else {

code/go/0chain.net/blobber/zcn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func setupServerChain() error {
103103
return err
104104
}
105105

106+
if node.Self.GetWallet().IsSplit {
107+
zcncore.RegisterZauthServer(serverChain.ZauthServer)
108+
}
109+
106110
fmt.Print(" [OK]\n")
107111
return nil
108112
}

code/go/0chain.net/blobbercore/handler/protocol.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package handler
33
import (
44
"context"
55
"errors"
6+
"sync"
7+
68
"github.com/0chain/gosdk/core/client"
79
coreTxn "github.com/0chain/gosdk/core/transaction"
8-
"sync"
910

1011
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
1112
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"

code/go/0chain.net/core/chain/entity.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func NewChainFromConfig() *Chain {
5151
chain.ID = common.ToKey(config.Configuration.ChainID)
5252
chain.OwnerID = viper.GetString("server_chain.owner")
5353
chain.BlockWorker = viper.GetString("block_worker")
54+
chain.ZauthServer = viper.GetString("zauth_server")
5455
return chain
5556
}
5657

code/go/0chain.net/core/node/self_node.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"encoding/json"
66
"fmt"
7+
78
"github.com/0chain/blobber/code/go/0chain.net/core/common"
89
"github.com/0chain/blobber/code/go/0chain.net/core/config"
910
"github.com/0chain/gosdk/core/zcncrypto"
@@ -19,20 +20,43 @@ type SelfNode struct {
1920
}
2021

2122
/*SetKeys - setter */
22-
func (sn *SelfNode) SetKeys(publicKey, privateKey string) {
23-
publicKeyBytes, err := hex.DecodeString(publicKey)
23+
func (sn *SelfNode) SetKeys(clientKey, publicKey, privateKey string, isSplit bool) {
24+
var (
25+
publicKeyBytes []byte
26+
err error
27+
)
28+
29+
if isSplit {
30+
publicKeyBytes, err = hex.DecodeString(clientKey)
31+
} else {
32+
publicKeyBytes, err = hex.DecodeString(publicKey)
33+
}
34+
2435
if err != nil {
2536
panic(err)
2637
}
38+
2739
sn.wallet = &zcncrypto.Wallet{}
2840
sn.wallet.ClientID = Hash(publicKeyBytes)
29-
sn.wallet.ClientKey = publicKey
41+
42+
if isSplit {
43+
sn.wallet.ClientKey = clientKey
44+
} else {
45+
sn.wallet.ClientKey = publicKey
46+
}
47+
3048
sn.wallet.Keys = make([]zcncrypto.KeyPair, 1)
3149
sn.wallet.Keys[0].PublicKey = publicKey
3250
sn.wallet.Keys[0].PrivateKey = privateKey
3351
sn.wallet.Version = zcncrypto.CryptoVersion
52+
sn.wallet.IsSplit = isSplit
53+
54+
if isSplit {
55+
sn.PublicKey = clientKey
56+
} else {
57+
sn.PublicKey = publicKey
58+
}
3459

35-
sn.PublicKey = publicKey
3660
sn.ID = sn.wallet.ClientID
3761
}
3862

code/go/0chain.net/validator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func main() {
107107
fmt.Println("using validator keys from aws")
108108
}
109109

110-
node.Self.SetKeys(publicKey, privateKey)
110+
node.Self.SetKeys("", publicKey, privateKey, false)
111111

112112
if len(*hostUrl) > 0 {
113113
node.Self.URL = *hostUrl

code/go/0chain.net/validatorcore/storage/models_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,6 @@ func setupModelsTest(t *testing.T) error {
659659
return err
660660
}
661661

662-
node.Self.SetKeys(wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey)
662+
node.Self.SetKeys("", wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey, false)
663663
return nil
664664
}

config/0chain_blobber.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ min_confirmation: 10
4545

4646
block_worker: https://dev.0chain.net/dns
4747

48+
zauth_server: https://zauth.dev.0chain.net/
49+
4850
rate_limiters:
4951
# Rate limiters will use this duration to clean unused token buckets.
5052
# If it is 0 then token will expire in 10 years.

0 commit comments

Comments
 (0)