Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(pkg): add StringToBytes32 method
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed May 15, 2023
1 parent 506694f commit 0ed5244
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
5 changes: 1 addition & 4 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ func InitFromConfig(ctx context.Context, d *Driver, cfg *Config) (err error) {
log.Warn("P2P syncing verified blocks enabled, but no connected peer found in L2 execution engine")
}

var signalServiceNameBytes [32]byte
copy(signalServiceNameBytes[:], []byte("signal_service"))

signalServiceAddress, err := d.rpc.TaikoL1.Resolve0(nil, signalServiceNameBytes, false)
signalServiceAddress, err := d.rpc.TaikoL1.Resolve0(nil, rpc.StringToBytes32("signal_service"), false)
if err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ func GetReceiptsByBlock(ctx context.Context, cli *rpc.Client, block *types.Block
func SetHead(ctx context.Context, rpc *rpc.Client, headNum *big.Int) error {
return gethclient.New(rpc).SetHead(ctx, headNum)
}

// StringToBytes32 converts the given string to [32]byte.
func StringToBytes32(str string) [32]byte {
var b [32]byte
copy(b[:], []byte(str))

return b
}
5 changes: 5 additions & 0 deletions pkg/rpc/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ func TestGetReceiptsByBlock(t *testing.T) {
func TestSetHead(t *testing.T) {
require.Nil(t, SetHead(context.Background(), newTestClient(t).L2RawRPC, common.Big0))
}

func TestStringToBytes32(t *testing.T) {
require.Equal(t, [32]byte{}, StringToBytes32(""))
require.Equal(t, [32]byte{0x61, 0x62, 0x63}, StringToBytes32("abc"))
}
16 changes: 10 additions & 6 deletions prover/proof_producer/special_proof_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type SpecialProofProducer struct {
// NewSpecialProofProducer creates a new NewSpecialProofProducer instance, which can be either
// an oracle proof producer, or a system proofproducer.
func NewSpecialProofProducer(
rpc *rpc.Client,
rpcClient *rpc.Client,
proverPrivKey *ecdsa.PrivateKey,
taikoL2Address common.Address,
proofTimeTarget time.Duration,
Expand All @@ -49,15 +49,19 @@ func NewSpecialProofProducer(
return nil, errProtocolAddressMismatch
}

anchorValidator, err := anchorTxValidator.New(taikoL2Address, rpc.L2ChainID, rpc)
anchorValidator, err := anchorTxValidator.New(taikoL2Address, rpcClient.L2ChainID, rpcClient)
if err != nil {
return nil, err
}

var graffitiBytes [32]byte
copy(graffitiBytes[:], []byte(graffiti))

return &SpecialProofProducer{rpc, proverPrivKey, anchorValidator, proofTimeTarget, graffitiBytes, isSystemProver}, nil
return &SpecialProofProducer{
rpcClient,
proverPrivKey,
anchorValidator,
proofTimeTarget,
rpc.StringToBytes32(graffiti),
isSystemProver,
}, nil
}

// RequestProof implements the ProofProducer interface.
Expand Down
18 changes: 6 additions & 12 deletions prover/proof_submitter/valid_proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ValidProofSubmitter struct {

// NewValidProofSubmitter creates a new ValidProofSubmitter instance.
func NewValidProofSubmitter(
rpc *rpc.Client,
rpcClient *rpc.Client,
proofProducer proofProducer.ProofProducer,
resultCh chan *proofProducer.ProofWithHeader,
taikoL2Address common.Address,
Expand All @@ -52,29 +52,23 @@ func NewValidProofSubmitter(
isSystemProver bool,
graffiti string,
) (*ValidProofSubmitter, error) {
anchorValidator, err := anchorTxValidator.New(taikoL2Address, rpc.L2ChainID, rpc)
anchorValidator, err := anchorTxValidator.New(taikoL2Address, rpcClient.L2ChainID, rpcClient)
if err != nil {
return nil, err
}

var signalServiceNameBytes [32]byte
copy(signalServiceNameBytes[:], []byte("signal_service"))

l1SignalService, err := rpc.TaikoL1.Resolve0(nil, signalServiceNameBytes, false)
l1SignalService, err := rpcClient.TaikoL1.Resolve0(nil, rpc.StringToBytes32("signal_service"), false)
if err != nil {
return nil, err
}

l2SignalService, err := rpc.TaikoL2.Resolve0(nil, signalServiceNameBytes, false)
l2SignalService, err := rpcClient.TaikoL2.Resolve0(nil, rpc.StringToBytes32("signal_service"), false)
if err != nil {
return nil, err
}

var graffitiBytes [32]byte
copy(graffitiBytes[:], []byte(graffiti))

return &ValidProofSubmitter{
rpc: rpc,
rpc: rpcClient,
proofProducer: proofProducer,
resultCh: resultCh,
anchorTxValidator: anchorValidator,
Expand All @@ -86,7 +80,7 @@ func NewValidProofSubmitter(
mutex: mutex,
isOracleProver: isOracleProver,
isSystemProver: isSystemProver,
graffiti: graffitiBytes,
graffiti: rpc.StringToBytes32(graffiti),
}, nil
}

Expand Down
10 changes: 2 additions & 8 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,14 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {
p.proposeConcurrencyGuard = make(chan struct{}, cfg.MaxConcurrentProvingJobs)
p.submitProofConcurrencyGuard = make(chan struct{}, cfg.MaxConcurrentProvingJobs)

oracleProverName := [32]byte{}
copy(oracleProverName[:], "oracle_prover")

oracleProverAddress, err := p.rpc.TaikoL1.Resolve(nil, p.rpc.L1ChainID, oracleProverName, true)
oracleProverAddress, err := p.rpc.TaikoL1.Resolve(nil, p.rpc.L1ChainID, rpc.StringToBytes32("oracle_prover"), true)
if err != nil {
return err
}

p.oracleProverAddress = oracleProverAddress

systemProverName := [32]byte{}
copy(systemProverName[:], "system_prover")

systemProverAddress, err := p.rpc.TaikoL1.Resolve(nil, p.rpc.L1ChainID, systemProverName, true)
systemProverAddress, err := p.rpc.TaikoL1.Resolve(nil, p.rpc.L1ChainID, rpc.StringToBytes32("system_prover"), true)
if err != nil {
return err
}
Expand Down

0 comments on commit 0ed5244

Please sign in to comment.