Skip to content

Commit

Permalink
remove keypair from interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Jan 15, 2025
1 parent cab9487 commit 41a573a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 28 deletions.
2 changes: 0 additions & 2 deletions core/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ type Writer interface {
// will be returned.
RegisterOperator(
ctx context.Context,
keypair *KeyPair,
signer blssigner.Signer,
socket string,
quorumIds []QuorumID,
Expand All @@ -159,7 +158,6 @@ type Writer interface {
// with the provided signature from the churner
RegisterOperatorWithChurn(
ctx context.Context,
keypair *KeyPair,
signer blssigner.Signer,
socket string,
quorumIds []QuorumID,
Expand Down
2 changes: 0 additions & 2 deletions core/eth/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func NewWriter(
// will be returned.
func (t *Writer) RegisterOperator(
ctx context.Context,
keypair *core.KeyPair,
signer blssigner.Signer,
socket string,
quorumIds []core.QuorumID,
Expand Down Expand Up @@ -104,7 +103,6 @@ func (t *Writer) RegisterOperator(
// with the provided signature from the churner
func (t *Writer) RegisterOperatorWithChurn(
ctx context.Context,
keypair *core.KeyPair,
signer blssigner.Signer,
socket string,
quorumIds []core.QuorumID,
Expand Down
5 changes: 1 addition & 4 deletions core/indexer/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ func mustRegisterOperators(env *deploy.Config, logger logging.Logger) {
})
Expect(err).To(BeNil())

keyPair, err := core.MakeKeyPairFromString(op.NODE_TEST_PRIVATE_BLS)
Expect(err).To(BeNil())

socket := fmt.Sprintf("%v:%v", op.NODE_HOSTNAME, op.NODE_DISPERSAL_PORT)

salt := [32]byte{}
Expand All @@ -72,7 +69,7 @@ func mustRegisterOperators(env *deploy.Config, logger logging.Logger) {
privKey, err := crypto.HexToECDSA(op.NODE_PRIVATE_KEY)
Expect(err).To(BeNil())

err = tx.RegisterOperator(context.Background(), keyPair, signer, socket, quorums, privKey, salt, expiry)
err = tx.RegisterOperator(context.Background(), signer, socket, quorums, privKey, salt, expiry)
Expect(err).To(BeNil())
}
}
Expand Down
6 changes: 2 additions & 4 deletions core/mock/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,27 @@ func (t *MockWriter) GetRegisteredQuorumIdsForOperator(ctx context.Context, oper

func (t *MockWriter) RegisterOperator(
ctx context.Context,
keypair *core.KeyPair,
signer blssigner.Signer,
socket string,
quorumIds []core.QuorumID,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
operatorToAvsRegistrationSigSalt [32]byte,
operatorToAvsRegistrationSigExpiry *big.Int,
) error {
args := t.Called(ctx, keypair, signer, socket, quorumIds, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
args := t.Called(ctx, signer, socket, quorumIds, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
return args.Error(0)
}

func (t *MockWriter) RegisterOperatorWithChurn(
ctx context.Context,
keypair *core.KeyPair,
signer blssigner.Signer,
socket string,
quorumIds []core.QuorumID,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
operatorToAvsRegistrationSigSalt [32]byte,
operatorToAvsRegistrationSigExpiry *big.Int,
churnReply *churner.ChurnReply) error {
args := t.Called(ctx, keypair, signer, socket, quorumIds, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry, churnReply)
args := t.Called(ctx, signer, socket, quorumIds, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry, churnReply)
return args.Error(0)
}

Expand Down
1 change: 0 additions & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ func (n *Node) Start(ctx context.Context) error {
Socket: socket,
Timeout: 10 * time.Second,
PrivKey: privateKey,
KeyPair: n.KeyPair,
Signer: n.BLSSigner,
OperatorId: n.Config.ID,
QuorumIDs: n.Config.QuorumIDList,
Expand Down
5 changes: 2 additions & 3 deletions node/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type Operator struct {
Socket string
Timeout time.Duration
PrivKey *ecdsa.PrivateKey
KeyPair *core.KeyPair
Signer blssigner.Signer
OperatorId core.OperatorID
QuorumIDs []core.QuorumID
Expand Down Expand Up @@ -91,10 +90,10 @@ func RegisterOperator(ctx context.Context, operator *Operator, transactor core.W
return fmt.Errorf("failed to request churn approval: %w", err)
}

return transactor.RegisterOperatorWithChurn(ctx, operator.KeyPair, operator.Signer, operator.Socket, quorumsToRegister, operator.PrivKey, salt, expiry, churnReply)
return transactor.RegisterOperatorWithChurn(ctx, operator.Signer, operator.Socket, quorumsToRegister, operator.PrivKey, salt, expiry, churnReply)
} else {
// other wise just register normally
return transactor.RegisterOperator(ctx, operator.KeyPair, operator.Signer, operator.Socket, quorumsToRegister, operator.PrivKey, salt, expiry)
return transactor.RegisterOperator(ctx, operator.Signer, operator.Socket, quorumsToRegister, operator.PrivKey, salt, expiry)
}
}

Expand Down
14 changes: 9 additions & 5 deletions node/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestRegisterOperator(t *testing.T) {
Socket: "localhost:50051",
Timeout: 10 * time.Second,
PrivKey: nil,
KeyPair: keyPair,
Signer: signer,
OperatorId: operatorID,
QuorumIDs: []core.QuorumID{0, 1},
Expand All @@ -49,7 +48,7 @@ func TestRegisterOperator(t *testing.T) {
ChurnBIPsOfTotalStake: 20000,
}, nil)
tx.On("GetNumberOfRegisteredOperatorForQuorum").Return(uint32(0), nil)
tx.On("RegisterOperator", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
tx.On("RegisterOperator", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
return tx

}
Expand All @@ -70,13 +69,18 @@ func TestRegisterOperatorWithChurn(t *testing.T) {
operatorID := [32]byte(hexutil.MustDecode("0x3fbfefcdc76462d2cdb7d0cea75f27223829481b8b4aa6881c94cb2126a316ad"))
keyPair, err := core.GenRandomBlsKeys()
assert.NoError(t, err)
signer, err := blssigner.NewSigner(blssignerTypes.SignerConfig{
PrivateKey: keyPair.PrivKey.String(),
SignerType: blssignerTypes.PrivateKey,
})
assert.NoError(t, err)
// Create a new operator
operator := &node.Operator{
Address: "0xB7Ad27737D88B07De48CDc2f379917109E993Be4",
Socket: "localhost:50051",
Timeout: 10 * time.Second,
Signer: signer,
PrivKey: nil,
KeyPair: keyPair,
OperatorId: operatorID,
QuorumIDs: []core.QuorumID{1},
}
Expand All @@ -88,10 +92,10 @@ func TestRegisterOperatorWithChurn(t *testing.T) {
ChurnBIPsOfTotalStake: 20000,
}, nil)
tx.On("GetNumberOfRegisteredOperatorForQuorum").Return(uint32(1), nil)
tx.On("RegisterOperatorWithChurn", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
tx.On("RegisterOperatorWithChurn", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
churnerClient := &nodemock.ChurnerClient{}
churnerClient.On("Churn").Return(nil, nil)
err = node.RegisterOperator(context.Background(), operator, tx, churnerClient, logger)
assert.NoError(t, err)
tx.AssertCalled(t, "RegisterOperatorWithChurn", mock.Anything, mock.Anything, mock.Anything, mock.Anything, []core.QuorumID{1}, mock.Anything, mock.Anything, mock.Anything, mock.Anything)
tx.AssertCalled(t, "RegisterOperatorWithChurn", mock.Anything, mock.Anything, mock.Anything, []core.QuorumID{1}, mock.Anything, mock.Anything, mock.Anything, mock.Anything)
}
9 changes: 2 additions & 7 deletions operators/churner/tests/churner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ func TestChurner(t *testing.T) {
g1point := &core.G1Point{
G1Affine: kp.PubKey.G1Affine,
}
opKeyPair := &core.KeyPair{
PrivKey: kp.PrivKey,
PubKey: g1point,
}
sk, privateKey, err := plugin.GetECDSAPrivateKey(op.NODE_ECDSA_KEY_FILE, op.NODE_ECDSA_KEY_PASSWORD)
assert.NoError(t, err)
if i == 0 {
Expand All @@ -139,12 +135,11 @@ func TestChurner(t *testing.T) {
if i >= testConfig.Services.Counts.NumMaxOperatorCount {
// This operator will churn others
operatorAddr = sk.Address.Hex()
keyPair = opKeyPair
signer = opSigner
operatorPrivateKey = sk.PrivateKey
break
}
err = tx.RegisterOperator(ctx, opKeyPair, opSigner, socket, quorumIDsUint8, sk.PrivateKey, salt, expiry)
err = tx.RegisterOperator(ctx, opSigner, socket, quorumIDsUint8, sk.PrivateKey, salt, expiry)
assert.NoError(t, err)
}
assert.Greater(t, len(lowestStakeOperatorAddr), 0)
Expand Down Expand Up @@ -194,7 +189,7 @@ func TestChurner(t *testing.T) {
salt32 := [32]byte{}
copy(salt32[:], salt)
expiry := big.NewInt((time.Now().Add(10 * time.Minute)).Unix())
err = tx.RegisterOperatorWithChurn(ctx, keyPair, signer, "localhost:8080", quorumIDsUint8, operatorPrivateKey, salt32, expiry, reply)
err = tx.RegisterOperatorWithChurn(ctx, signer, "localhost:8080", quorumIDsUint8, operatorPrivateKey, salt32, expiry, reply)
assert.NoError(t, err)
}

Expand Down

0 comments on commit 41a573a

Please sign in to comment.