Skip to content

Commit

Permalink
Added the ability to pass the proposer pub key to the mock settlement…
Browse files Browse the repository at this point in the history
… config. (#182)
  • Loading branch information
omritoptix authored Jan 11, 2023
1 parent d808ecb commit 55a4e81
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package block
import (
"context"
"crypto/rand"
"encoding/hex"
"encoding/json"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -450,7 +451,7 @@ func initSettlementLayerMock(settlementlc settlement.LayerClient, batchSize uint
Config: &settlement.Config{
BatchSize: batchSize,
},
ProposerPubKey: proposerPubKey,
ProposerPubKey: hex.EncodeToString(proposerPubKey),
}
byteconf, _ := json.Marshal(conf)
err := settlementlc.Init(byteconf, pubsubServer, logger)
Expand Down
5 changes: 3 additions & 2 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"context"
crand "crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"math/rand"
Expand Down Expand Up @@ -410,7 +411,7 @@ func TestTx(t *testing.T) {
require.NoError(err)

proposerPubKeyBytes, err := proposerPubKey.Raw()
settlementLayerConfig, err := json.Marshal(slmock.Config{ProposerPubKey: proposerPubKeyBytes})
settlementLayerConfig, err := json.Marshal(slmock.Config{ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)})
require.NoError(err)

node, err := node.NewNode(context.Background(), config.NodeConfig{
Expand Down Expand Up @@ -658,7 +659,7 @@ func TestValidatorSetHandling(t *testing.T) {
require.NoError(err)

proposerPubKeyBytes, err := proposerPubKey.Raw()
settlementLayerConfig, err := json.Marshal(slmock.Config{ProposerPubKey: proposerPubKeyBytes})
settlementLayerConfig, err := json.Marshal(slmock.Config{ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)})
require.NoError(err)

vKeys := make([]tmcrypto.PrivKey, 4)
Expand Down
3 changes: 2 additions & 1 deletion rpc/json/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -292,7 +293,7 @@ func getRPC(t *testing.T) (*mocks.Application, *client.Client) {
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
signingKey, proposerPubKey, _ := crypto.GenerateEd25519Key(rand.Reader)
proposerPubKeyBytes, err := proposerPubKey.Raw()
settlementLayerConfig, err := json.Marshal(slmock.Config{ProposerPubKey: proposerPubKeyBytes})
settlementLayerConfig, err := json.Marshal(slmock.Config{ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)})
require.NoError(err)
config := config.NodeConfig{Aggregator: true, DALayer: "mock", SettlementLayer: "mock", BlockManagerConfig: config.BlockManagerConfig{BlockTime: 1 * time.Second, BatchSyncInterval: time.Second}, SettlementConfig: string(settlementLayerConfig)}
node, err := node.NewNode(context.Background(), config, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
Expand Down
20 changes: 18 additions & 2 deletions settlement/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package mock
import (
"context"
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"strings"
"sync/atomic"

tmp2p "github.com/tendermint/tendermint/p2p"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
rollapptypes "github.com/dymensionxyz/dymension/x/rollapp/types"
"github.com/dymensionxyz/dymint/da"
Expand Down Expand Up @@ -58,7 +62,7 @@ type Config struct {
*settlement.Config
DBPath string `json:"db_path"`
RootDir string `json:"root_dir"`
ProposerPubKey []byte `json:"proposer_pub_key"`
ProposerPubKey string `json:"proposer_pub_key"`
store store.KVStore
}

Expand Down Expand Up @@ -143,6 +147,14 @@ func getConfig(config []byte) (*Config, error) {
} else {
conf.store = store.NewDefaultInMemoryKVStore()
}
// If the proposer pub key is a path, load the key from the file. otherwise, use the key as is.
if strings.HasSuffix(string(conf.ProposerPubKey), ".json") {
key, err := tmp2p.LoadOrGenNodeKey(string(conf.ProposerPubKey))
if err != nil {
return nil, err
}
conf.ProposerPubKey = hex.EncodeToString(key.PubKey().Bytes())
}
} else {
conf = &Config{
store: store.NewDefaultInMemoryKVStore(),
Expand Down Expand Up @@ -203,7 +215,11 @@ func (c *HubClient) GetBatchAtIndex(rollappID string, index uint64) (*settlement

// GetSequencers returns a list of sequencers. Currently only returns a single sequencer
func (c *HubClient) GetSequencers(rollappID string) ([]*types.Sequencer, error) {
pubKey := &ed25519.PubKey{Key: c.config.ProposerPubKey}
pubKeyBytes, err := hex.DecodeString(c.config.ProposerPubKey)
if err != nil {
return nil, err
}
pubKey := &ed25519.PubKey{Key: pubKeyBytes}
return []*types.Sequencer{
{
PublicKey: pubKey,
Expand Down

0 comments on commit 55a4e81

Please sign in to comment.