Skip to content

Commit 10bd095

Browse files
feat(chain): introduce tron KMS signer (#272)
To introduce kms signer for TRON, i have to perform a interface refactor so the existing generator does not return a keystore but instead a sign hash function as KMS does not expose the keystore. Will get some people from tron side to review this.
1 parent 6025781 commit 10bd095

14 files changed

+998
-291
lines changed

.changeset/common-bats-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": minor
3+
---
4+
5+
Introdce KMS signer for TRON

chain/tron/provider/account_generator.go

Lines changed: 0 additions & 86 deletions
This file was deleted.

chain/tron/provider/account_generator_test.go

Lines changed: 0 additions & 117 deletions
This file was deleted.

chain/tron/provider/ctf_provider.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import (
3030

3131
// CTFChainProviderConfig holds the configuration to initialize the CTFChainProvider.
3232
type CTFChainProviderConfig struct {
33-
// Required: A generator for the deployer account. Use AccountGenCTFDefault to
34-
// create a deployer account from the default CTF account. Alternatively, you can use
35-
// AccountRandom to create a new random account.
36-
DeployerAccountGen AccountGenerator
33+
// Required: A generator for the deployer signer. Use SignerGenCTFDefault to
34+
// create a deployer signer from the default CTF account. Alternatively, you can use
35+
// SignerRandom to create a new random signer.
36+
DeployerSignerGen SignerGenerator
3737

3838
// Required: A sync.Once instance to ensure that the CTF framework only sets up the new
3939
// DefaultNetwork once
@@ -42,8 +42,8 @@ type CTFChainProviderConfig struct {
4242

4343
// validate checks whether the configuration contains all required values.
4444
func (c CTFChainProviderConfig) validate() error {
45-
if c.DeployerAccountGen == nil {
46-
return errors.New("deployer account generator is required")
45+
if c.DeployerSignerGen == nil {
46+
return errors.New("deployer signer generator is required")
4747
}
4848
if c.Once == nil {
4949
return errors.New("sync.Once instance is required")
@@ -121,23 +121,23 @@ func (p *CTFChainProvider) Initialize(_ context.Context) (chain.BlockChain, erro
121121
return nil, fmt.Errorf("failed to create combined client: %w", err)
122122
}
123123

124-
// Generate deployer keystore and address
125-
deployerKeystore, deployerAddr, err := p.config.DeployerAccountGen.Generate()
124+
// Get deployer address from the signer generator
125+
deployerAddr, err := p.config.DeployerSignerGen.GetAddress()
126126
if err != nil {
127-
return nil, fmt.Errorf("failed to generate deployer account: %w", err)
127+
return nil, fmt.Errorf("failed to get deployer address: %w", err)
128128
}
129129

130-
// Initialize local RPC client wrapper that uses the keystore for signing
131-
client := rpcclient.New(combinedClient, deployerKeystore, deployerAddr)
130+
// Initialize local RPC client wrapper that uses the signer generator's signing function
131+
client := rpcclient.New(combinedClient, p.config.DeployerSignerGen.Sign)
132132

133133
// Construct and cache the Tron chain instance with helper methods for deploying and interacting with contracts
134134
p.chain = &tron.Chain{
135135
ChainMetadata: tron.ChainMetadata{
136136
Selector: p.selector,
137137
},
138-
Client: combinedClient, // Underlying client for Tron node communication
139-
Keystore: deployerKeystore, // Keystore for signing transactions
140-
Address: deployerAddr, // Default "from" address for transactions
138+
Client: combinedClient, // Underlying client for Tron node communication
139+
SignHash: p.config.DeployerSignerGen.Sign, // Function for signing transactions
140+
Address: deployerAddr, // Default "from" address for transactions
141141
URL: fullNodeURL,
142142
// Helper for sending and confirming transactions
143143
SendAndConfirm: func(ctx context.Context, tx *common.Transaction, opts *tron.ConfirmRetryOptions) (*soliditynode.TransactionInfo, error) {

chain/tron/provider/ctf_provider_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ func TestCTFChainProviderConfig_validate(t *testing.T) {
2525
{
2626
name: "empty config",
2727
config: CTFChainProviderConfig{},
28-
expectedErr: "deployer account generator is required",
28+
expectedErr: "deployer signer generator is required",
2929
},
3030
{
3131
name: "missing sync.Once",
3232
config: CTFChainProviderConfig{
33-
DeployerAccountGen: AccountGenCTFDefault(),
33+
DeployerSignerGen: SignerGenCTFDefault(),
3434
},
3535
expectedErr: "sync.Once instance is required",
3636
},
3737
{
3838
name: "valid config",
3939
config: CTFChainProviderConfig{
40-
DeployerAccountGen: AccountGenCTFDefault(),
41-
Once: &sync.Once{},
40+
DeployerSignerGen: SignerGenCTFDefault(),
41+
Once: &sync.Once{},
4242
},
4343
expectedErr: "",
4444
},
@@ -62,8 +62,8 @@ func TestNewCTFChainProvider(t *testing.T) {
6262
t.Parallel()
6363

6464
config := CTFChainProviderConfig{
65-
DeployerAccountGen: AccountGenCTFDefault(),
66-
Once: &sync.Once{},
65+
DeployerSignerGen: SignerGenCTFDefault(),
66+
Once: &sync.Once{},
6767
}
6868

6969
provider := NewCTFChainProvider(t, 123456, config)
@@ -87,8 +87,8 @@ func TestCTFChainProvider_Initialize(t *testing.T) {
8787
name: "valid initialization",
8888
giveSelector: chain_selectors.TRON_TESTNET_NILE.Selector,
8989
giveConfig: CTFChainProviderConfig{
90-
DeployerAccountGen: AccountGenCTFDefault(),
91-
Once: &sync.Once{},
90+
DeployerSignerGen: SignerGenCTFDefault(),
91+
Once: &sync.Once{},
9292
},
9393
},
9494
{
@@ -97,22 +97,22 @@ func TestCTFChainProvider_Initialize(t *testing.T) {
9797
giveConfig: CTFChainProviderConfig{
9898
Once: &sync.Once{},
9999
},
100-
wantErr: "deployer account generator is required",
100+
wantErr: "deployer signer generator is required",
101101
},
102102
{
103103
name: "missing sync.Once",
104104
giveSelector: chain_selectors.TRON_TESTNET_NILE.Selector,
105105
giveConfig: CTFChainProviderConfig{
106-
DeployerAccountGen: AccountGenCTFDefault(),
106+
DeployerSignerGen: SignerGenCTFDefault(),
107107
},
108108
wantErr: "sync.Once instance is required",
109109
},
110110
{
111111
name: "chain id not found for selector",
112112
giveSelector: 999999, // Invalid selector
113113
giveConfig: CTFChainProviderConfig{
114-
DeployerAccountGen: AccountGenCTFDefault(),
115-
Once: &sync.Once{},
114+
DeployerSignerGen: SignerGenCTFDefault(),
115+
Once: &sync.Once{},
116116
},
117117
wantErr: "failed to get chain ID from selector 999999",
118118
},
@@ -136,7 +136,7 @@ func TestCTFChainProvider_Initialize(t *testing.T) {
136136
require.True(t, ok, "expected got to be of type tron.Chain")
137137
require.Equal(t, tt.giveSelector, gotChain.Selector)
138138
require.NotEmpty(t, gotChain.Client)
139-
require.NotEmpty(t, gotChain.Keystore)
139+
require.NotEmpty(t, gotChain.SignHash)
140140
require.NotEmpty(t, gotChain.Address)
141141
require.NotEmpty(t, gotChain.URL)
142142
require.NotEmpty(t, gotChain.SendAndConfirm)
@@ -150,8 +150,8 @@ func TestCTFChainProvider_Initialize(t *testing.T) {
150150
func TestCTFChainProvider_ContainerStartup(t *testing.T) {
151151
t.Parallel()
152152
config := CTFChainProviderConfig{
153-
DeployerAccountGen: AccountGenCTFDefault(),
154-
Once: &sync.Once{},
153+
DeployerSignerGen: SignerGenCTFDefault(),
154+
Once: &sync.Once{},
155155
}
156156

157157
provider := NewCTFChainProvider(t, chain_selectors.TRON_TESTNET_NILE.Selector, config)
@@ -169,8 +169,8 @@ func TestCTFProvider_SendAndConfirmTx_And_CheckContractDeployed(t *testing.T) {
169169
t.Parallel()
170170

171171
config := CTFChainProviderConfig{
172-
DeployerAccountGen: AccountGenCTFDefault(),
173-
Once: &sync.Once{},
172+
DeployerSignerGen: SignerGenCTFDefault(),
173+
Once: &sync.Once{},
174174
}
175175

176176
chainSelector := chain_selectors.TRON_TESTNET_NILE.Selector

0 commit comments

Comments
 (0)