Skip to content

Commit

Permalink
Fix PR review comments
Browse files Browse the repository at this point in the history
Signed-off-by: rodion <[email protected]>
  • Loading branch information
rodion-lim-partior committed Jul 1, 2024
1 parent 55a8385 commit c78b926
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 138 deletions.
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func validateQuorumConsensus(consensusString string) error {
}

if v != types.QuorumConsensusClique {
return errors.New("support for raft/ibft/qbft will come in future")
return errors.New("consensus algorithms such as raft/ibft/qbft for quorum not supported")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/blockchain/ethereum/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
type Account struct {
Address string `json:"address"`
PrivateKey string `json:"privateKey"`
PtmPublicKey string `json:"ptmPublicKey"`
PtmPublicKey string `json:"ptmPublicKey"` // Public key used for Tessera
}

func GenerateAddressAndPrivateKey() (address string, privateKey string) {
Expand Down
8 changes: 4 additions & 4 deletions internal/blockchain/ethereum/quorum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"net/http"
)

type GethClient struct {
type QuorumClient struct {
rpcURL string
}

Expand All @@ -47,13 +47,13 @@ type JSONRPCError struct {
Message string `json:"message"`
}

func NewGethClient(rpcURL string) *GethClient {
return &GethClient{
func NewQuorumClient(rpcURL string) *QuorumClient {
return &QuorumClient{
rpcURL: rpcURL,
}
}

func (g *GethClient) UnlockAccount(address string, password string) error {
func (g *QuorumClient) UnlockAccount(address string, password string) error {
requestBody, err := json.Marshal(&JSONRPCRequest{
JSONRPC: "2.0",
ID: 0,
Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/ethereum/quorum/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Alloc struct {

func CreateGenesis(addresses []string, blockPeriod int, chainID int64) *Genesis {
if blockPeriod == -1 {
blockPeriod = 0
blockPeriod = 5
}
extraData := "0x0000000000000000000000000000000000000000000000000000000000000000"
alloc := make(map[string]*Alloc)
Expand Down Expand Up @@ -92,7 +92,7 @@ func CreateGenesis(addresses []string, blockPeriod int, chainID int64) *Genesis
},
},
Nonce: "0x0",
Timestamp: "0x60edb1c7",
Timestamp: "0x0",
ExtraData: extraData,
GasLimit: "0xffffff",
Difficulty: "0x1",
Expand Down
2 changes: 1 addition & 1 deletion internal/blockchain/ethereum/quorum/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestCreateGenesis(t *testing.T) {
},
},
Nonce: "0x0",
Timestamp: "0x60edb1c7",
Timestamp: "0x0",
ExtraData: extraData,
GasLimit: "0xffffff",
Difficulty: "0x1",
Expand Down
19 changes: 8 additions & 11 deletions internal/blockchain/ethereum/quorum/private_transaction_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/hyperledger/firefly-cli/internal/docker"
)

var entrypoint = "docker-entrypoint.sh"
var DockerEntrypoint = "docker-entrypoint.sh"
var TmQ2tPort = "9101"
var TmTpPort = "9080"
var TmP2pPort = "9000"
var GethPort = "8545"
var QuorumPort = "8545"

type PrivateKeyData struct {
Bytes string `json:"bytes"`
Expand All @@ -43,7 +42,7 @@ type PrivateKey struct {
Data PrivateKeyData `json:"data"`
}

func CreateTesseraKeys(ctx context.Context, image, outputDirectory, prefix, name, password string) (privateKey, pubKey, path string, err error) {
func CreateTesseraKeys(ctx context.Context, image, outputDirectory, prefix, name string) (privateKey, pubKey, path string, err error) {
// generates both .pub and .key files used by Tessera
var filename string
if prefix != "" {
Expand Down Expand Up @@ -73,14 +72,13 @@ func CreateTesseraKeys(ctx context.Context, image, outputDirectory, prefix, name
if err != nil {
return "", "", "", err
}
return privateKeyData.Data.Bytes, string(pubKeyBytes[:]), path, nil
return privateKeyData.Data.Bytes, string(pubKeyBytes), path, nil
}

func CreateTesseraEntrypoint(ctx context.Context, outputDirectory, volumeName, memberCount, stackName string) error {
func CreateTesseraEntrypoint(ctx context.Context, outputDirectory, stackName string, memberCount int) error {
// only tessera v09 onwards is supported
var sb strings.Builder
memberCountInt, _ := strconv.Atoi(memberCount)
for i := 0; i < memberCountInt; i++ {
for i := 0; i < memberCount; i++ {
sb.WriteString(fmt.Sprintf("{\"url\":\"http://%s_member%dtessera:%s\"},", stackName, i, TmP2pPort)) // construct peer list
}
peerList := strings.TrimSuffix(sb.String(), ",")
Expand Down Expand Up @@ -144,7 +142,7 @@ cat <<EOF > ${DDIR}/tessera-config-09.json
EOF
/tessera/bin/tessera -configfile ${DDIR}/tessera-config-09.json
`, TmTpPort, TmQ2tPort, TmP2pPort, peerList)
filename := filepath.Join(outputDirectory, entrypoint)
filename := filepath.Join(outputDirectory, DockerEntrypoint)
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
return err
Expand All @@ -154,15 +152,14 @@ EOF
if err != nil {
return err
}
CopyTesseraEntrypointToVolume(ctx, outputDirectory, volumeName)
return nil
}

func CopyTesseraEntrypointToVolume(ctx context.Context, tesseraEntrypointDirectory, volumeName string) error {
if err := docker.MkdirInVolume(ctx, volumeName, ""); err != nil {
return err
}
if err := docker.CopyFileToVolume(ctx, volumeName, filepath.Join(tesseraEntrypointDirectory, entrypoint), ""); err != nil {
if err := docker.CopyFileToVolume(ctx, volumeName, filepath.Join(tesseraEntrypointDirectory, DockerEntrypoint), ""); err != nil {
return err
}
return nil
Expand Down
33 changes: 19 additions & 14 deletions internal/blockchain/ethereum/quorum/quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ import (
"github.com/hyperledger/firefly-cli/internal/docker"
)

func CreateQuorumEntrypoint(ctx context.Context, outputDirectory, volumeName, memberIndex, consensus, stackName string, chainId int, tesseraEnabled bool) error {
func CreateQuorumEntrypoint(ctx context.Context, outputDirectory, volumeName, consensus, stackName string, memberIndex, chainID, blockPeriodInSeconds int, tesseraEnabled bool) error {
discoveryCmd := "BOOTNODE_CMD=\"\""
connectTimeout := 15
if memberIndex != "0" {
discoveryCmd = fmt.Sprintf(`bootnode=$(curl http://geth_0:%s -s --connect-timeout %[2]d --max-time %[2]d --retry 5 --retry-connrefused --retry-delay 0 --retry-max-time 60 --fail --header "Content-Type: application/json" --data '{"jsonrpc":"2.0", "method": "admin_nodeInfo", "params": [], "id": 1}' | grep -o "enode://[a-z0-9@.:]*")
if memberIndex != 0 {
discoveryCmd = fmt.Sprintf(`bootnode=$(curl http://quorum_0:%s -s --connect-timeout %[2]d --max-time %[2]d --retry 5 --retry-connrefused --retry-delay 0 --retry-max-time 60 --fail --header "Content-Type: application/json" --data '{"jsonrpc":"2.0", "method": "admin_nodeInfo", "params": [], "id": 1}' | grep -o "enode://[a-z0-9@.:]*")
BOOTNODE_CMD="--bootnodes $bootnode"
BOOTNODE_CMD=${BOOTNODE_CMD/127.0.0.1/geth_0}`, GethPort, connectTimeout)
BOOTNODE_CMD=${BOOTNODE_CMD/127.0.0.1/quorum_0}`, QuorumPort, connectTimeout)
}

tesseraCmd := ""
if tesseraEnabled {
tesseraCmd = fmt.Sprintf(`TESSERA_URL=http://%[5]s_member%[1]stessera
tesseraCmd = fmt.Sprintf(`TESSERA_URL=http://%[5]s_member%[1]dtessera
TESSERA_TP_PORT=%[2]s
TESSERA_Q2T_PORT=%[3]s
TESSERA_UPCHECK_URL=$TESSERA_URL:$TESSERA_TP_PORT/upcheck
Expand All @@ -48,18 +48,24 @@ echo ""
`, memberIndex, TmTpPort, TmQ2tPort, connectTimeout, stackName)
}

blockPeriod := blockPeriodInSeconds
if blockPeriodInSeconds == -1 {
blockPeriod = 5
}
blockPeriodInMs := blockPeriod * 60

content := fmt.Sprintf(`#!/bin/sh
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace
GOQUORUM_CONS_ALGO=%s
GOQUORUM_CONS_ALGO=%[1]s
if [ "istanbul" == "$GOQUORUM_CONS_ALGO" ];
then
echo "Using istanbul for consensus algorithm..."
export CONSENSUS_ARGS="--istanbul.blockperiod 5 --mine --miner.threads 1 --miner.gasprice 0 --emitcheckpoints"
export CONSENSUS_ARGS="--istanbul.blockperiod %[6]d --mine --miner.threads 1 --miner.gasprice 0 --emitcheckpoints"
export QUORUM_API="istanbul"
elif [ "qbft" == "$GOQUORUM_CONS_ALGO" ];
then
Expand All @@ -69,7 +75,7 @@ then
elif [ "raft" == "$GOQUORUM_CONS_ALGO" ];
then
echo "Using raft for consensus algorithm..."
export CONSENSUS_ARGS="--raft --raftblocktime 300 --raftport 53000"
export CONSENSUS_ARGS="--raft --raftblocktime %[7]d --raftport 53000"
export QUORUM_API="raft"
elif [ "clique" == "$GOQUORUM_CONS_ALGO" ];
then
Expand All @@ -79,15 +85,15 @@ then
fi
ADDITIONAL_ARGS=${ADDITIONAL_ARGS:-}
%s
%[2]s
# discovery
%s
%[3]s
echo "bootnode discovery command :: $BOOTNODE_CMD"
IP_ADDR=$(cat /etc/hosts | tail -n 1 | awk '{print $1}')
exec geth --datadir /data --nat extip:$IP_ADDR --syncmode 'full' --revertreason --port 30311 --http --http.addr "0.0.0.0" --http.corsdomain="*" -http.port %s --http.vhosts "*" --http.api admin,personal,eth,net,web3,txpool,miner,debug,$QUORUM_API --networkid %d --miner.gasprice 0 --password /data/password --mine --allow-insecure-unlock --verbosity 4 $CONSENSUS_ARGS --miner.gaslimit 16777215 $BOOTNODE_CMD $ADDITIONAL_ARGS`, consensus, tesseraCmd, discoveryCmd, GethPort, chainId)
filename := filepath.Join(outputDirectory, entrypoint)
exec geth --datadir /data --nat extip:$IP_ADDR --syncmode 'full' --revertreason --port 30311 --http --http.addr "0.0.0.0" --http.corsdomain="*" -http.port %[4]s --http.vhosts "*" --http.api admin,personal,eth,net,web3,txpool,miner,debug,$QUORUM_API --networkid %[5]d --miner.gasprice 0 --password /data/password --mine --allow-insecure-unlock --verbosity 4 $CONSENSUS_ARGS --miner.gaslimit 16777215 $BOOTNODE_CMD $ADDITIONAL_ARGS`, consensus, tesseraCmd, discoveryCmd, QuorumPort, chainID, blockPeriod, blockPeriodInMs)
filename := filepath.Join(outputDirectory, DockerEntrypoint)
if err := os.MkdirAll(outputDirectory, 0755); err != nil {
return err
}
Expand All @@ -100,12 +106,11 @@ exec geth --datadir /data --nat extip:$IP_ADDR --syncmode 'full' --revertreason
if err != nil {
return err
}
CopyQuorumEntrypointToVolume(ctx, outputDirectory, volumeName)
return nil
}

func CopyQuorumEntrypointToVolume(ctx context.Context, quorumEntrypointDirectory, volumeName string) error {
if err := docker.CopyFileToVolume(ctx, volumeName, filepath.Join(quorumEntrypointDirectory, entrypoint), ""); err != nil {
if err := docker.CopyFileToVolume(ctx, volumeName, filepath.Join(quorumEntrypointDirectory, DockerEntrypoint), ""); err != nil {
return err
}
return nil
Expand Down
Loading

0 comments on commit c78b926

Please sign in to comment.