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

Fx for new bridge deployment issues: 837, 838, 839, 840, 841, 842 #886

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Changes from 1 commit
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
Next Next commit
fix for wrong topic_id acc and wrapped token decimals - 839, 841
Signed-off-by: Stanislav Viyachev <[email protected]>
Coiling-Dragon committed Apr 11, 2023

Verified

This commit was signed with the committer’s verified signature.
sourabhxyz Sourabh
commit 63bab7016f59feb168da9ab6629ee889f0a2bb18
2 changes: 1 addition & 1 deletion scripts/bridge/setup/cmd/setup.go
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ func main() {

// pass empty array of private keys since we are using this script for new accounts
hederaPrivateKeys := make([]hedera.PrivateKey, 0)
result := setup.Deploy(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, topicThreshold)
result := setup.Deploy(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, *topicThreshold)
if result.Error != nil {
panic(result.Error)
}
46 changes: 33 additions & 13 deletions scripts/bridge/setup/from-config/cmd/setup-from-config.go
Original file line number Diff line number Diff line change
@@ -19,9 +19,15 @@ package main
import (
"flag"
"fmt"
"math"

"github.com/hashgraph/hedera-sdk-go/v2"
"github.com/limechain/hedera-eth-bridge-validator/config"
cfgParser "github.com/limechain/hedera-eth-bridge-validator/config/parser"

// cfgParser "github.com/limechain/hedera-eth-bridge-validator/config/parser"
"io/ioutil"
"strings"

"github.com/limechain/hedera-eth-bridge-validator/constants"
bridgeSetup "github.com/limechain/hedera-eth-bridge-validator/scripts/bridge/setup"
"github.com/limechain/hedera-eth-bridge-validator/scripts/bridge/setup/parser"
@@ -31,8 +37,6 @@ import (
nativeNftCreate "github.com/limechain/hedera-eth-bridge-validator/scripts/token/native/nft/create"
wrappedFungibleCreate "github.com/limechain/hedera-eth-bridge-validator/scripts/token/wrapped/create"
"gopkg.in/yaml.v2"
"io/ioutil"
"strings"
)

const (
@@ -52,8 +56,8 @@ func main() {
members := flag.Int("members", 1, "The count of the members")
memberPrivateKeys := flag.String("memberPrivateKeys", "", "Member private keys array, seperated by ','")
adminKey := flag.String("adminKey", "", "The admin key")
topicThreshold := flag.Uint("topicThreshold", 1, "Topic member keys sign threshold")
wrappedFungibleThreshold := flag.Uint("wrappedTokenThreshold", 1, "The desired threshold of n/m keys required for supply key of wrapped tokens")
// topicThreshold := flag.Uint("topicThreshold", 1, "Topic member keys sign threshold")
// wrappedFungibleThreshold := flag.Uint("wrappedTokenThreshold", 1, "The desired threshold of n/m keys required for supply key of wrapped tokens")
configPath := flag.String("configPath", "scripts/bridge/setup/extend-config/extended-bridge.yml", "Path to the 'bridge.yaml' config file")
flag.Parse()

@@ -71,16 +75,18 @@ func main() {
}
}

validateArguments(privateKey, accountID, adminKey, topicThreshold, members, configPath, network)
treshold := uint(math.Ceil(float64(*members) * float64(0.51)))

validateArguments(privateKey, accountID, adminKey, members, configPath, network)
if *network == "testnet" {
hederaNetworkId = HederaTestnetNetworkId
} else {
hederaNetworkId = HederaMainnetNetworkId
}
parsedBridgeCfgForDeploy := parseExtendedBridge(configPath)
bridgeDeployResult := deployBridge(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, topicThreshold, parsedBridgeCfgForDeploy)
bridgeDeployResult := deployBridge(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, treshold, parsedBridgeCfgForDeploy)
createAndAssociateTokens(
wrappedFungibleThreshold,
&treshold,
bridgeDeployResult,
privateKey,
accountID,
@@ -89,7 +95,7 @@ func main() {
)

printTitle("Updated Bridge yaml config:")
newBridgeYml, err := yaml.Marshal(cfgParser.Config{Bridge: *parsedBridgeCfgForDeploy.ToBridgeParser()})
newBridgeYml, err := yaml.Marshal(*parsedBridgeCfgForDeploy.ToBridgeParser())
if err != nil {
panic(fmt.Sprintf("Failed to marshal updated bridge config to yaml. Err: [%s]", err))
}
@@ -118,9 +124,9 @@ func createAndAssociateTokens(wrappedFungibleThreshold *uint, bridgeDeployResult
fmt.Println("====================================")
}

func deployBridge(privateKey *string, accountID *string, adminKey *string, network *string, members *int, hederaPrivateKeys []hedera.PrivateKey, topicThreshold *uint, parsedBridgeCfgForDeploy *parser.ExtendedBridge) bridgeSetup.DeployResult {
func deployBridge(privateKey *string, accountID *string, adminKey *string, network *string, members *int, hederaPrivateKeys []hedera.PrivateKey, treshold uint, parsedBridgeCfgForDeploy *parser.ExtendedBridge) bridgeSetup.DeployResult {
printTitle("Starting Deployment of Bridge ...")
bridgeDeployResult := bridgeSetup.Deploy(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, topicThreshold)
bridgeDeployResult := bridgeSetup.Deploy(privateKey, accountID, adminKey, network, members, hederaPrivateKeys, treshold)
if bridgeDeployResult.Error != nil {
panic(bridgeDeployResult.Error)
}
@@ -130,6 +136,17 @@ func deployBridge(privateKey *string, accountID *string, adminKey *string, netwo
for index, accountId := range bridgeDeployResult.MembersAccountIDs {
parsedBridgeCfgForDeploy.Networks[hederaNetworkId].Members[index] = accountId.String()
}
monitored_accounts := map[string]string{}
var index_of_monitored_account int = 0
for key, _ := range parsedBridgeCfgForDeploy.MonitoredAccounts {
monitored_accounts[key] = bridgeDeployResult.MembersAccountIDs[index_of_monitored_account].String()
index_of_monitored_account++
}
parsedBridgeCfgForDeploy.MonitoredAccounts = monitored_accounts
parsedBridgeCfgForDeploy.TopicId = bridgeDeployResult.TopicId.String()

// TODO: redeplo the config topic and assign the new topic id to the config
parsedBridgeCfgForDeploy.ConfigTopicId = "0.0.0"

fmt.Println("====================================")
return bridgeDeployResult
@@ -151,6 +168,9 @@ func createAndAssociateWrappedTokens(network uint64, networkInfo *parser.Network
if _, ok := tokenInfo.Networks[hederaNetworkId]; !ok {
continue
}
if tokenInfo.Decimals > 8 {
tokenInfo.Decimals = 8
}
fmt.Printf("Creating Hedera Wrapped Fungible Token based on info of token with address [%s] ...\n", tokenAddress)
tokenId, err := wrappedFungibleCreate.WrappedFungibleToken(
client,
@@ -261,8 +281,8 @@ func associateToken(tokenId *hedera.TokenID, client *hedera.Client, accountId he
return err
}

func validateArguments(privateKey *string, accountID *string, adminKey *string, topicThreshold *uint, members *int, configPath *string, network *string) {
err := bridgeSetup.ValidateArguments(privateKey, accountID, adminKey, topicThreshold, members)
func validateArguments(privateKey *string, accountID *string, adminKey *string, members *int, configPath *string, network *string) {
err := bridgeSetup.ValidateArguments(privateKey, accountID, adminKey, members)
if err != nil {
panic(err)
}
1 change: 1 addition & 0 deletions scripts/bridge/setup/parser/extended-bridge.go
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ func (b *ExtendedBridge) ToBridgeParser() *parser.Bridge {
parsedBridge.ConfigTopicId = b.ConfigTopicId
parsedBridge.PollingInterval = b.PollingInterval
parsedBridge.TopicId = b.TopicId
// parsedBridge.
parsedBridge.MonitoredAccounts = b.MonitoredAccounts
parsedBridge.Networks = make(map[uint64]*parser.Network)

23 changes: 13 additions & 10 deletions scripts/bridge/setup/setup.go
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ package setup
import (
"errors"
"fmt"
"math"
// "math"

"github.com/limechain/hedera-eth-bridge-validator/scripts/client"

@@ -38,10 +38,10 @@ type DeployResult struct {
Error error
}

func Deploy(privateKey *string, accountID *string, adminKey *string, network *string, members *int, previousPrivateKeys []hedera.PrivateKey, topicThreshold *uint) DeployResult {
func Deploy(privateKey *string, accountID *string, adminKey *string, network *string, members *int, previousPrivateKeys []hedera.PrivateKey, treshold uint) DeployResult {
result := DeployResult{}

err := ValidateArguments(privateKey, accountID, adminKey, topicThreshold, members)
err := ValidateArguments(privateKey, accountID, adminKey, members)
if err != nil {
result.Error = err
return result
@@ -69,8 +69,11 @@ func Deploy(privateKey *string, accountID *string, adminKey *string, network *st
}
fmt.Println("Members Private keys array:", result.MembersPrivateKeys)

//
result.MembersPublicKeys = make([]hedera.PublicKey, 0, *members)
topicKey := hedera.KeyListWithThreshold(*topicThreshold)

// treshold is 1 because each validator should be able to post to the gossip topic
topicKey := hedera.KeyListWithThreshold(1)
for i := 0; i < *members; i++ {
pubKey := result.MembersPrivateKeys[i].PublicKey()
result.MembersPublicKeys = append(result.MembersPublicKeys, pubKey)
@@ -102,8 +105,8 @@ func Deploy(privateKey *string, accountID *string, adminKey *string, network *st
fmt.Printf("TopicID: %v\n", topicReceipt.TopicID)
fmt.Println("--------------------------")

treshold := math.Ceil(float64(*members) * float64(0.51))
custodialKey := hedera.KeyListWithThreshold(uint(treshold))
// treshold := uint(math.Ceil(float64(*members) * float64(0.51)))
custodialKey := hedera.KeyListWithThreshold(treshold)
for i := 0; i < *members; i++ {
custodialKey.Add(result.MembersPublicKeys[i])
}
@@ -149,7 +152,7 @@ func Deploy(privateKey *string, accountID *string, adminKey *string, network *st
return result
}

func ValidateArguments(privateKey *string, accountID *string, adminKey *string, topicThreshold *uint, members *int) error {
func ValidateArguments(privateKey *string, accountID *string, adminKey *string, members *int) error {
if *privateKey == "0x0" {
return errors.New("private key was not provided")
}
@@ -159,9 +162,9 @@ func ValidateArguments(privateKey *string, accountID *string, adminKey *string,
if *adminKey == "" {
return errors.New("admin key not provided")
}
if *topicThreshold > uint(*members) {
return errors.New("threshold can't be more than the members count")
}
// if *topicThreshold > uint(*members) {
// return errors.New("threshold can't be more than the members count")
// }

return nil
}