Skip to content

Commit

Permalink
pass test with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Jul 26, 2024
1 parent 4354830 commit f66c337
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
7 changes: 4 additions & 3 deletions aggoracle/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ var (
)

type Config struct {
TargetChainType TargetChainType `mapstructure:"TargetChainType"`
EVMSender chaingersender.EVMConfig `mapstructure:"EVMSender"`
URLRPCL1 string `mapstructure:"URLRPCL1"`
TargetChainType TargetChainType `mapstructure:"TargetChainType"`
URLRPCL1 string `mapstructure:"URLRPCL1"`
// TODO: BlockFinality doesnt work as per the jsonschema
BlockFinality string `jsonschema:"enum=latest,enum=safe, enum=pending, enum=finalized" mapstructure:"BlockFinality"`
WaitPeriodNextGER types.Duration `mapstructure:"WaitPeriodNextGER"`
EVMSender chaingersender.EVMConfig `mapstructure:"EVMSender"`
}
6 changes: 5 additions & 1 deletion aggoracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ func (a *AggOracle) Start(ctx context.Context) {
case <-a.ticker.C:
gerToInject, err := a.getLastFinalisedGER(ctx)
if err != nil {
log.Error("error calling getLastFinalisedGER: ", err)
if err == l1infotreesync.ErrBlockNotProcessed || err == l1infotreesync.ErrNotFound {
log.Debugf("syncer is not ready: %v", err)
} else {
log.Error("error calling isGERAlreadyInjected: ", err)
}
continue
}
if alreadyInjectd, err := a.chainSender.IsGERAlreadyInjected(gerToInject); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ func createAggoracle(cfg config.Config, l1Client *ethclient.Client, syncer *l1in
Outputs: cfg.Log.Outputs,
}
ethTxManager, err := ethtxmanager.New(cfg.AggOracle.EVMSender.EthTxManager)
if err != nil {
log.Fatal(err)
}
go ethTxManager.Start()
l2CLient, err := ethclient.Dial(cfg.AggOracle.EVMSender.URLRPCL2)
if err != nil {
log.Fatal(err)
Expand Down
43 changes: 20 additions & 23 deletions l1infotreesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/0xPolygon/cdk/common"
"github.com/0xPolygon/cdk/l1infotree"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/sync"
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ledgerwatch/erigon-lib/kv"
Expand Down Expand Up @@ -186,7 +187,8 @@ func (p *processor) GetInfoByRoot(ctx context.Context, root ethCommon.Hash) (*L1
return p.getInfoByHashWithTx(tx, hash)
}

// GetLatestInfoUntilBlock returns the most recent L1InfoTreeLeaf that occured before or at blockNum
// GetLatestInfoUntilBlock returns the most recent L1InfoTreeLeaf that occured before or at blockNum.
// If the blockNum has not been processed yet the error ErrBlockNotProcessed will be returned
func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*L1InfoTreeLeaf, error) {
tx, err := p.db.BeginRo(ctx)
if err != nil {
Expand All @@ -197,32 +199,26 @@ func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64
if lpb < blockNum {
return nil, ErrBlockNotProcessed
}
c, err := tx.Cursor(blockTable)
iter, err := tx.RangeDescend(blockTable, uint64ToBytes(blockNum), uint64ToBytes(0), 1)
if err != nil {
return nil, err
}
defer c.Close()
for k, v, err := c.Seek(uint64ToBytes(blockNum)); k != nil; k, v, err = c.Prev() {
if err != nil {
return nil, err
}
if bytes2Uint64(k) > blockNum {
// Seek function returns matching key or greater, therefore
// we could bed ealing with a block number greater than expected
continue
}
blk := blockWithLeafs{}
if err := json.Unmarshal(v, &blk); err != nil {
return nil, err
}
hash, err := tx.GetOne(indexTable, common.Uint32ToBytes(blk.LastIndex-1))
if err != nil {
return nil, err
}
return p.getInfoByHashWithTx(tx, hash)
if !iter.HasNext() {
return nil, ErrNotFound
}

return nil, ErrNotFound
_, v, err := iter.Next()
if err != nil {
return nil, err
}
blk := blockWithLeafs{}
if err := json.Unmarshal(v, &blk); err != nil {
return nil, err
}
hash, err := tx.GetOne(indexTable, common.Uint32ToBytes(blk.LastIndex-1))
if err != nil {
return nil, err
}
return p.getInfoByHashWithTx(tx, hash)
}

func (p *processor) GetInfoByIndex(ctx context.Context, index uint32) (*L1InfoTreeLeaf, error) {
Expand Down Expand Up @@ -424,6 +420,7 @@ func (p *processor) ProcessBlock(b sync.Block) error {
tx.Rollback()
return err
}
log.Debugf("block %d processed with events: %+v", b.Num, b.Events)
return tx.Commit()
}

Expand Down

0 comments on commit f66c337

Please sign in to comment.