From f460553f9eee8aea136da011c8eb201a6b3a0450 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 15 Jan 2025 21:15:42 +0100 Subject: [PATCH 1/5] feature: added split key option --- code/go/0chain.net/blobber/flags.go | 30 ++++++++++--------- code/go/0chain.net/blobber/node.go | 2 +- code/go/0chain.net/core/node/self_node.go | 4 ++- code/go/0chain.net/validator/main.go | 2 +- .../validatorcore/storage/models_test.go | 2 +- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/code/go/0chain.net/blobber/flags.go b/code/go/0chain.net/blobber/flags.go index 83537bc25..c39164d35 100644 --- a/code/go/0chain.net/blobber/flags.go +++ b/code/go/0chain.net/blobber/flags.go @@ -6,26 +6,28 @@ import ( ) var ( - deploymentMode int - keysFile string - keysFileRaw string - mountPoint string - metadataDB string - logDir string - httpPort int - hostname string - configDir string - grpcPort int - httpsPort int - httpsKeyFile string - httpsCertFile string - hostUrl string + deploymentMode int + keysFile string + keysFileRaw string + keysFileIsSplit bool + mountPoint string + metadataDB string + logDir string + httpPort int + hostname string + configDir string + grpcPort int + httpsPort int + httpsKeyFile string + httpsCertFile string + hostUrl string ) func init() { flag.IntVar(&deploymentMode, "deployment_mode", 2, "deployment mode: 0=dev,1=test, 2=mainnet") flag.StringVar(&keysFile, "keys_file", "", "keys_file") flag.StringVar(&keysFileRaw, "keys_file_raw", "", "keys_file_raw") + flag.BoolVar(&keysFileIsSplit, "keys_file_is_split", false, "keys_file_is_split") flag.StringVar(&mountPoint, "files_dir", "", "Mounted partition where all files will be stored") flag.StringVar(&metadataDB, "db_dir", "", "db_dir") flag.StringVar(&logDir, "log_dir", "", "log_dir") diff --git a/code/go/0chain.net/blobber/node.go b/code/go/0chain.net/blobber/node.go index 50bfdca30..adc20a772 100644 --- a/code/go/0chain.net/blobber/node.go +++ b/code/go/0chain.net/blobber/node.go @@ -38,7 +38,7 @@ func setupNode() error { } } - node.Self.SetKeys(publicKey, privateKey) + node.Self.SetKeys(publicKey, privateKey, keysFileIsSplit) if node.Self.ID == "" { return errors.New("node definition for self node doesn't exist") } else { diff --git a/code/go/0chain.net/core/node/self_node.go b/code/go/0chain.net/core/node/self_node.go index c58692f59..af16a0282 100644 --- a/code/go/0chain.net/core/node/self_node.go +++ b/code/go/0chain.net/core/node/self_node.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/0chain/blobber/code/go/0chain.net/core/common" "github.com/0chain/blobber/code/go/0chain.net/core/config" "github.com/0chain/gosdk/core/zcncrypto" @@ -19,7 +20,7 @@ type SelfNode struct { } /*SetKeys - setter */ -func (sn *SelfNode) SetKeys(publicKey, privateKey string) { +func (sn *SelfNode) SetKeys(publicKey, privateKey string, isSplit bool) { publicKeyBytes, err := hex.DecodeString(publicKey) if err != nil { panic(err) @@ -31,6 +32,7 @@ func (sn *SelfNode) SetKeys(publicKey, privateKey string) { sn.wallet.Keys[0].PublicKey = publicKey sn.wallet.Keys[0].PrivateKey = privateKey sn.wallet.Version = zcncrypto.CryptoVersion + sn.wallet.IsSplit = isSplit sn.PublicKey = publicKey sn.ID = sn.wallet.ClientID diff --git a/code/go/0chain.net/validator/main.go b/code/go/0chain.net/validator/main.go index 6d9ac2c3a..6f4b42a37 100644 --- a/code/go/0chain.net/validator/main.go +++ b/code/go/0chain.net/validator/main.go @@ -107,7 +107,7 @@ func main() { fmt.Println("using validator keys from aws") } - node.Self.SetKeys(publicKey, privateKey) + node.Self.SetKeys(publicKey, privateKey, false) if len(*hostUrl) > 0 { node.Self.URL = *hostUrl diff --git a/code/go/0chain.net/validatorcore/storage/models_test.go b/code/go/0chain.net/validatorcore/storage/models_test.go index 149bd1928..46cdf4450 100644 --- a/code/go/0chain.net/validatorcore/storage/models_test.go +++ b/code/go/0chain.net/validatorcore/storage/models_test.go @@ -659,6 +659,6 @@ func setupModelsTest(t *testing.T) error { return err } - node.Self.SetKeys(wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey) + node.Self.SetKeys(wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey, false) return nil } From 6c4ff11e5aa37d93d5be00954ceea542c2151b68 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Thu, 16 Jan 2025 01:51:25 +0100 Subject: [PATCH 2/5] fix: fixed bugs --- code/go/0chain.net/blobber/zcn.go | 4 ++++ code/go/0chain.net/core/chain/entity.go | 1 + config/0chain_blobber.yaml | 2 ++ 3 files changed, 7 insertions(+) diff --git a/code/go/0chain.net/blobber/zcn.go b/code/go/0chain.net/blobber/zcn.go index 31a7f9122..301ed43fd 100644 --- a/code/go/0chain.net/blobber/zcn.go +++ b/code/go/0chain.net/blobber/zcn.go @@ -103,6 +103,10 @@ func setupServerChain() error { return err } + if node.Self.GetWallet().IsSplit { + zcncore.RegisterZauthServer(serverChain.ZauthServer) + } + fmt.Print(" [OK]\n") return nil } diff --git a/code/go/0chain.net/core/chain/entity.go b/code/go/0chain.net/core/chain/entity.go index 28a71904b..0c3adf562 100644 --- a/code/go/0chain.net/core/chain/entity.go +++ b/code/go/0chain.net/core/chain/entity.go @@ -51,6 +51,7 @@ func NewChainFromConfig() *Chain { chain.ID = common.ToKey(config.Configuration.ChainID) chain.OwnerID = viper.GetString("server_chain.owner") chain.BlockWorker = viper.GetString("block_worker") + chain.ZauthServer = viper.GetString("zauth_server") return chain } diff --git a/config/0chain_blobber.yaml b/config/0chain_blobber.yaml index c7864e651..d277d6cb2 100755 --- a/config/0chain_blobber.yaml +++ b/config/0chain_blobber.yaml @@ -45,6 +45,8 @@ min_confirmation: 10 block_worker: https://dev.0chain.net/dns +zauth_server: https://zauth.dev.0chain.net/ + rate_limiters: # Rate limiters will use this duration to clean unused token buckets. # If it is 0 then token will expire in 10 years. From fddb26b05113c92e9bf03f7a5f25010ddacb7f19 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Thu, 16 Jan 2025 10:57:11 +0100 Subject: [PATCH 3/5] fix: changed arguments --- code/go/0chain.net/blobber/flags.go | 34 +++++++++++++++-------------- code/go/0chain.net/blobber/node.go | 6 +++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/code/go/0chain.net/blobber/flags.go b/code/go/0chain.net/blobber/flags.go index c39164d35..400e933eb 100644 --- a/code/go/0chain.net/blobber/flags.go +++ b/code/go/0chain.net/blobber/flags.go @@ -6,27 +6,29 @@ import ( ) var ( - deploymentMode int - keysFile string - keysFileRaw string - keysFileIsSplit bool - mountPoint string - metadataDB string - logDir string - httpPort int - hostname string - configDir string - grpcPort int - httpsPort int - httpsKeyFile string - httpsCertFile string - hostUrl string + deploymentMode int + keysFile string + keysFilePublicKey string + keysFilePrivateKey string + keysFileIsSplit bool + mountPoint string + metadataDB string + logDir string + httpPort int + hostname string + configDir string + grpcPort int + httpsPort int + httpsKeyFile string + httpsCertFile string + hostUrl string ) func init() { flag.IntVar(&deploymentMode, "deployment_mode", 2, "deployment mode: 0=dev,1=test, 2=mainnet") flag.StringVar(&keysFile, "keys_file", "", "keys_file") - flag.StringVar(&keysFileRaw, "keys_file_raw", "", "keys_file_raw") + flag.StringVar(&keysFilePublicKey, "keys_file_public_key", "", "keys_file_public_key") + flag.StringVar(&keysFilePrivateKey, "keys_file_private_key", "", "keys_file_private_key") flag.BoolVar(&keysFileIsSplit, "keys_file_is_split", false, "keys_file_is_split") flag.StringVar(&mountPoint, "files_dir", "", "Mounted partition where all files will be stored") flag.StringVar(&metadataDB, "db_dir", "", "db_dir") diff --git a/code/go/0chain.net/blobber/node.go b/code/go/0chain.net/blobber/node.go index adc20a772..7e4dc44dc 100644 --- a/code/go/0chain.net/blobber/node.go +++ b/code/go/0chain.net/blobber/node.go @@ -21,8 +21,9 @@ func setupNode() error { var err error - if keysFileRaw != "" { - err = readKeysFromString(&keysFileRaw) + if keysFilePrivateKey != "" || keysFilePublicKey != "" { + privateKey = keysFilePrivateKey + publicKey = keysFilePublicKey fmt.Println("using blobber keys from local string") } else { @@ -39,6 +40,7 @@ func setupNode() error { } node.Self.SetKeys(publicKey, privateKey, keysFileIsSplit) + if node.Self.ID == "" { return errors.New("node definition for self node doesn't exist") } else { From a410da3b53182ed3bfe4f04f1211824be641d316 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Thu, 16 Jan 2025 11:27:33 +0100 Subject: [PATCH 4/5] feature: added client key arg option --- code/go/0chain.net/blobber/flags.go | 2 ++ code/go/0chain.net/blobber/node.go | 8 ++++++-- code/go/0chain.net/core/node/self_node.go | 15 +++++++++++++-- code/go/0chain.net/validator/main.go | 2 +- .../validatorcore/storage/models_test.go | 2 +- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/code/go/0chain.net/blobber/flags.go b/code/go/0chain.net/blobber/flags.go index 400e933eb..052c328ee 100644 --- a/code/go/0chain.net/blobber/flags.go +++ b/code/go/0chain.net/blobber/flags.go @@ -10,6 +10,7 @@ var ( keysFile string keysFilePublicKey string keysFilePrivateKey string + keysFileClientKey string keysFileIsSplit bool mountPoint string metadataDB string @@ -29,6 +30,7 @@ func init() { flag.StringVar(&keysFile, "keys_file", "", "keys_file") flag.StringVar(&keysFilePublicKey, "keys_file_public_key", "", "keys_file_public_key") flag.StringVar(&keysFilePrivateKey, "keys_file_private_key", "", "keys_file_private_key") + flag.StringVar(&keysFileClientKey, "keys_file_client_key", "", "keys_file_client_key") flag.BoolVar(&keysFileIsSplit, "keys_file_is_split", false, "keys_file_is_split") flag.StringVar(&mountPoint, "files_dir", "", "Mounted partition where all files will be stored") flag.StringVar(&metadataDB, "db_dir", "", "db_dir") diff --git a/code/go/0chain.net/blobber/node.go b/code/go/0chain.net/blobber/node.go index 7e4dc44dc..27e1d2091 100644 --- a/code/go/0chain.net/blobber/node.go +++ b/code/go/0chain.net/blobber/node.go @@ -14,7 +14,7 @@ import ( "go.uber.org/zap" ) -var publicKey, privateKey string +var clientKey, publicKey, privateKey string func setupNode() error { fmt.Println("> setup blobber") @@ -25,6 +25,10 @@ func setupNode() error { privateKey = keysFilePrivateKey publicKey = keysFilePublicKey + if keysFileIsSplit { + clientKey = keysFileClientKey + } + fmt.Println("using blobber keys from local string") } else { err = readKeysFromAws() @@ -39,7 +43,7 @@ func setupNode() error { } } - node.Self.SetKeys(publicKey, privateKey, keysFileIsSplit) + node.Self.SetKeys(clientKey, publicKey, privateKey, keysFileIsSplit) if node.Self.ID == "" { return errors.New("node definition for self node doesn't exist") diff --git a/code/go/0chain.net/core/node/self_node.go b/code/go/0chain.net/core/node/self_node.go index af16a0282..bcbba76b3 100644 --- a/code/go/0chain.net/core/node/self_node.go +++ b/code/go/0chain.net/core/node/self_node.go @@ -20,11 +20,22 @@ type SelfNode struct { } /*SetKeys - setter */ -func (sn *SelfNode) SetKeys(publicKey, privateKey string, isSplit bool) { - publicKeyBytes, err := hex.DecodeString(publicKey) +func (sn *SelfNode) SetKeys(clientKey, publicKey, privateKey string, isSplit bool) { + var ( + publicKeyBytes []byte + err error + ) + + if isSplit { + publicKeyBytes, err = hex.DecodeString(clientKey) + } else { + publicKeyBytes, err = hex.DecodeString(publicKey) + } + if err != nil { panic(err) } + sn.wallet = &zcncrypto.Wallet{} sn.wallet.ClientID = Hash(publicKeyBytes) sn.wallet.ClientKey = publicKey diff --git a/code/go/0chain.net/validator/main.go b/code/go/0chain.net/validator/main.go index 6f4b42a37..b34ee63ed 100644 --- a/code/go/0chain.net/validator/main.go +++ b/code/go/0chain.net/validator/main.go @@ -107,7 +107,7 @@ func main() { fmt.Println("using validator keys from aws") } - node.Self.SetKeys(publicKey, privateKey, false) + node.Self.SetKeys("", publicKey, privateKey, false) if len(*hostUrl) > 0 { node.Self.URL = *hostUrl diff --git a/code/go/0chain.net/validatorcore/storage/models_test.go b/code/go/0chain.net/validatorcore/storage/models_test.go index 46cdf4450..f7140d310 100644 --- a/code/go/0chain.net/validatorcore/storage/models_test.go +++ b/code/go/0chain.net/validatorcore/storage/models_test.go @@ -659,6 +659,6 @@ func setupModelsTest(t *testing.T) error { return err } - node.Self.SetKeys(wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey, false) + node.Self.SetKeys("", wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey, false) return nil } From cd3007d3d792dc92328189b2d43ec262680081ec Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Thu, 16 Jan 2025 14:08:54 +0100 Subject: [PATCH 5/5] fix: fixed public key management when split key mode is enabled --- .../go/0chain.net/blobbercore/handler/protocol.go | 3 ++- code/go/0chain.net/core/node/self_node.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/code/go/0chain.net/blobbercore/handler/protocol.go b/code/go/0chain.net/blobbercore/handler/protocol.go index 9bd7384d6..34b788fe8 100644 --- a/code/go/0chain.net/blobbercore/handler/protocol.go +++ b/code/go/0chain.net/blobbercore/handler/protocol.go @@ -3,9 +3,10 @@ package handler import ( "context" "errors" + "sync" + "github.com/0chain/gosdk/core/client" coreTxn "github.com/0chain/gosdk/core/transaction" - "sync" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/config" diff --git a/code/go/0chain.net/core/node/self_node.go b/code/go/0chain.net/core/node/self_node.go index bcbba76b3..ea75baf41 100644 --- a/code/go/0chain.net/core/node/self_node.go +++ b/code/go/0chain.net/core/node/self_node.go @@ -38,14 +38,25 @@ func (sn *SelfNode) SetKeys(clientKey, publicKey, privateKey string, isSplit boo sn.wallet = &zcncrypto.Wallet{} sn.wallet.ClientID = Hash(publicKeyBytes) - sn.wallet.ClientKey = publicKey + + if isSplit { + sn.wallet.ClientKey = clientKey + } else { + sn.wallet.ClientKey = publicKey + } + sn.wallet.Keys = make([]zcncrypto.KeyPair, 1) sn.wallet.Keys[0].PublicKey = publicKey sn.wallet.Keys[0].PrivateKey = privateKey sn.wallet.Version = zcncrypto.CryptoVersion sn.wallet.IsSplit = isSplit - sn.PublicKey = publicKey + if isSplit { + sn.PublicKey = clientKey + } else { + sn.PublicKey = publicKey + } + sn.ID = sn.wallet.ClientID }