Skip to content

Commit

Permalink
fix for wrong topic_id acc and wrapped token decimals - 839, 841
Browse files Browse the repository at this point in the history
Signed-off-by: Stanislav Viyachev <[email protected]>
  • Loading branch information
Coiling-Dragon committed Apr 11, 2023
1 parent b9089b6 commit 30847d1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion scripts/bridge/setup/cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
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
Expand Up @@ -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"
Expand All @@ -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 (
Expand All @@ -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()

Expand All @@ -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,
Expand All @@ -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))
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -241,8 +261,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)
}
Expand Down
1 change: 1 addition & 0 deletions scripts/bridge/setup/parser/extended-bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])
}
Expand Down Expand Up @@ -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")
}
Expand All @@ -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
}
Expand Down

0 comments on commit 30847d1

Please sign in to comment.