-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/oasis-test-runner: Add sentry node support
- Loading branch information
Showing
6 changed files
with
252 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ package oasis | |
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/oasislabs/oasis-core/go/client" | ||
"github.com/oasislabs/oasis-core/go/common/crypto/signature" | ||
|
@@ -273,6 +275,36 @@ func (args *argBuilder) sentryControlPort(port uint16) *argBuilder { | |
return args | ||
} | ||
|
||
func (args *argBuilder) addSentries(sentries []*Sentry) *argBuilder { | ||
addrs := []string{} | ||
certFiles := []string{} | ||
for _, sentry := range sentries { | ||
addrs = append(addrs, fmt.Sprintf("127.0.0.1:%d", sentry.controlPort)) | ||
certFiles = append(certFiles, sentry.TLSCertPath()) | ||
} | ||
args = args.workerSentryAddresses(strings.Join(addrs, ",")) | ||
args = args.workerSentryCertFiles(strings.Join(certFiles, ",")) | ||
return args | ||
} | ||
|
||
func (args *argBuilder) addSentriesAsPersistentPeers(sentries []*Sentry) *argBuilder { | ||
peers := []string{} | ||
for _, sentry := range sentries { | ||
peers = append(peers, fmt.Sprintf("%[email protected]:%d", sentry.consensusAddress, sentry.consensusPort)) | ||
} | ||
args = args.tendermintPersistentPeers(strings.Join(peers, ",")) | ||
return args | ||
} | ||
|
||
func (args *argBuilder) addValidatorsAsPrivatePeers(validators []*Validator) *argBuilder { | ||
peers := []string{} | ||
for _, val := range validators { | ||
peers = append(peers, fmt.Sprintf("%[email protected]:%d", val.consensusAddress, val.consensusPort)) | ||
} | ||
args = args.tendermintPrivatePeers(strings.Join(peers, ",")) | ||
return args | ||
} | ||
|
||
func (args *argBuilder) appendSeedNodes(net *Network) *argBuilder { | ||
if seed := net.seedNode; seed != nil { | ||
args.vec = append(args.vec, []string{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package oasis | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/oasislabs/oasis-core/go/common/crypto/signature" | ||
fileSigner "github.com/oasislabs/oasis-core/go/common/crypto/signature/signers/file" | ||
"github.com/oasislabs/oasis-core/go/common/identity" | ||
"github.com/oasislabs/oasis-core/go/oasis-test-runner/env" | ||
"github.com/oasislabs/oasis-core/go/tendermint/crypto" | ||
) | ||
|
||
// Sentry is an Oasis sentry node. | ||
type Sentry struct { | ||
net *Network | ||
dir *env.Dir | ||
|
||
validatorIndices []int | ||
|
||
consensusPublicKey signature.PublicKey | ||
consensusAddress string | ||
consensusPort uint16 | ||
controlPort uint16 | ||
} | ||
|
||
// SentryCfg is the Oasis sentry node configuration. | ||
type SentryCfg struct { | ||
ValidatorIndices []int | ||
} | ||
|
||
// LogPath returns the path to the node's log. | ||
func (sentry *Sentry) LogPath() string { | ||
return nodeLogPath(sentry.dir) | ||
} | ||
|
||
// TLSCertPath returns the path to the node's TLS certificate. | ||
func (sentry *Sentry) TLSCertPath() string { | ||
return nodeTLSCertPath(sentry.dir) | ||
} | ||
|
||
func (sentry *Sentry) startNode() error { | ||
validators, err := resolveValidators(sentry.net, sentry.validatorIndices) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
args := newArgBuilder(). | ||
debugAllowTestKeys(). | ||
sentry(). | ||
tendermintCoreListenAddress(sentry.consensusPort). | ||
sentryControlPort(sentry.controlPort). | ||
appendNetwork(sentry.net). | ||
addValidatorsAsPrivatePeers(validators) | ||
|
||
if _, err := sentry.net.startOasisNode(sentry.dir, nil, args, "sentry", false, false); err != nil { | ||
return fmt.Errorf("oasis/sentry: failed to launch node: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// NewSentry provisions a new sentry node and adds it to the network. | ||
func (net *Network) NewSentry(cfg *SentryCfg) (*Sentry, error) { | ||
sentryName := fmt.Sprintf("sentry-%d", len(net.sentries)) | ||
|
||
sentryDir, err := net.baseDir.NewSubDir(sentryName) | ||
if err != nil { | ||
net.logger.Error("failed to create sentry subdir", | ||
"err", err, | ||
"sentry_name", sentryName, | ||
) | ||
return nil, fmt.Errorf("oasis/sentry: failed to create sentry subdir: %w", err) | ||
} | ||
|
||
// Pre-provision the node identity, so that we can pass the sentry node's | ||
// consensus public key and address to validator to configure the sentry | ||
// node as a persistent peer. | ||
signerFactory := fileSigner.NewFactory(sentryDir.String(), signature.SignerNode, signature.SignerP2P, signature.SignerConsensus) | ||
sentryIdentity, err := identity.LoadOrGenerate(sentryDir.String(), signerFactory) | ||
if err != nil { | ||
net.logger.Error("failed to provision sentry identity", | ||
"err", err, | ||
"sentry_name", sentryName, | ||
) | ||
return nil, fmt.Errorf("oasis/sentry: failed to provision sentry identity: %w", err) | ||
} | ||
sentryConsensusPublicKey := sentryIdentity.ConsensusSigner.Public() | ||
|
||
sentry := &Sentry{ | ||
net: net, | ||
dir: sentryDir, | ||
validatorIndices: cfg.ValidatorIndices, | ||
consensusPublicKey: sentryConsensusPublicKey, | ||
consensusAddress: crypto.PublicKeyToTendermint(&sentryConsensusPublicKey).Address().String(), | ||
consensusPort: net.nextNodePort, | ||
controlPort: net.nextNodePort + 1, | ||
} | ||
|
||
net.sentries = append(net.sentries, sentry) | ||
net.nextNodePort += 2 | ||
|
||
return sentry, nil | ||
} |
Oops, something went wrong.