Skip to content

Commit

Permalink
Use simple key generation source for faster account creation (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbertJordan authored Nov 20, 2024
1 parent 05a1fc3 commit d766f9c
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions load/app/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package app
import (
"context"
"crypto/ecdsa"
"encoding/binary"
"fmt"
"math/big"
"sync/atomic"
Expand All @@ -35,29 +36,25 @@ import (
// Any factory using the same mnemonic, feederId and appId produce the same sequence of accounts,
// which can be used to reuse existing accounts from previous runs.
type AccountFactory struct {
keyGenerator *KeyGenerator
chainID *big.Int
numAccounts int64
chainID *big.Int
numAccounts int64
}

// NewAccountFactory creates a new AccountFactory, generating accounts for given feeder and app.
// Re-creating a factory using the same feederId and appId will produce the same sequence of accounts.
func NewAccountFactory(chainID *big.Int, feederId, appId uint32) (*AccountFactory, error) {
keyGenerator, err := NewKeyGenerator(Mnemonic, feederId, appId)
if err != nil {
return nil, err
}
return &AccountFactory{
keyGenerator: keyGenerator,
chainID: chainID,
numAccounts: 0,
chainID: chainID,
numAccounts: 0,
}, nil
}

// CreateAccount generates the next account in the sequence generated by the AccountFactory.
func (f *AccountFactory) CreateAccount(rpcClient rpc.RpcClient) (*Account, error) {
id := atomic.AddInt64(&f.numAccounts, 1)
privateKey, err := f.keyGenerator.GeneratePrivateKey(uint32(id))
d := make([]byte, 32)
binary.BigEndian.PutUint64(d[:24], uint64(id))
privateKey, err := crypto.ToECDSA(d)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -131,10 +128,6 @@ func (a *Account) getNextNonce() uint64 {
return current - 1
}

func (a *Account) getCurrentNonce() uint64 {
return atomic.LoadUint64(&a.nonce)
}

// CreateValidator creates non genesis validator trough createValidator sfc call
func (a *Account) CreateValidator(SFCContract *contract.SFC, rpcClient rpc.RpcClient) (*types.Transaction, error) {
// get price of gas from the network
Expand Down

0 comments on commit d766f9c

Please sign in to comment.