Skip to content

Commit

Permalink
feat(eventindexer): Eventindexer and relayer a5 updates (#14597)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Aug 28, 2023
1 parent 2a9d194 commit 87c9d53
Show file tree
Hide file tree
Showing 40 changed files with 1,200 additions and 5,431 deletions.
727 changes: 0 additions & 727 deletions packages/eventindexer/ProverPool.json

Large diffs are not rendered by default.

539 changes: 203 additions & 336 deletions packages/eventindexer/TaikoL1.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/eventindexer/abigen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ if [ ! -d "../protocol/out" ]; then
exit 1
fi

paths=("TaikoL1.sol" "ProverPool.sol" "Bridge.sol")
paths=("TaikoL1.sol" "Bridge.sol")

names=("TaikoL1" "ProverPool" "Bridge")
names=("TaikoL1" "Bridge")


for (( i = 0; i < ${#paths[@]}; ++i ));
Expand Down
14 changes: 6 additions & 8 deletions packages/eventindexer/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func Run(
EthClient: ethClient,
RPCClient: rpcClient,
SrcTaikoAddress: common.HexToAddress(os.Getenv("L1_TAIKO_ADDRESS")),
ProverPoolAddress: common.HexToAddress(os.Getenv("PROVER_POOL_ADDRESS")),
SrcBridgeAddress: common.HexToAddress(os.Getenv("BRIDGE_ADDRESS")),
SrcSwapAddresses: stringsToAddresses(strings.Split(os.Getenv("SWAP_ADDRESSES"), ",")),
BlockBatchSize: uint64(blockBatchSize),
Expand Down Expand Up @@ -283,13 +282,12 @@ func newHTTPServer(db eventindexer.DB, l1EthClient *ethclient.Client) (*http.Ser
}

srv, err := http.NewServer(http.NewServerOpts{
EventRepo: eventRepo,
StatRepo: statRepo,
NFTBalanceRepo: nftBalanceRepo,
Echo: echo.New(),
CorsOrigins: strings.Split(os.Getenv("CORS_ORIGINS"), ","),
EthClient: l1EthClient,
ProverPoolAddress: common.HexToAddress(os.Getenv("PROVER_POOL_ADDRESS")),
EventRepo: eventRepo,
StatRepo: statRepo,
NFTBalanceRepo: nftBalanceRepo,
Echo: echo.New(),
CorsOrigins: strings.Split(os.Getenv("CORS_ORIGINS"), ","),
EthClient: l1EthClient,
})
if err != nil {
return nil, err
Expand Down
2,071 changes: 0 additions & 2,071 deletions packages/eventindexer/contracts/proverpool/ProverPool.go

This file was deleted.

680 changes: 283 additions & 397 deletions packages/eventindexer/contracts/taikol1/TaikoL1.go

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions packages/eventindexer/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ var (
EventNameBlockProven = "BlockProven"
EventNameBlockProposed = "BlockProposed"
EventNameBlockVerified = "BlockVerified"
EventNameSlashed = "Slashed"
EventNameMessageSent = "MessageSent"
EventNameSwap = "Swap"
EventNameStaked = "Staked"
EventNameExited = "Exited"
EventNameWithdrawn = "Withdrawn"
EventNameMint = "Mint"
EventNameNFTTransfer = "Transfer"
)
Expand Down Expand Up @@ -92,7 +88,6 @@ type EventRepository interface {
address string,
event string,
) (paginate.Page, error)
GetTotalSlashedTokens(ctx context.Context) (*big.Int, error)
FirstByAddressAndEventName(
ctx context.Context,
address string,
Expand Down
62 changes: 0 additions & 62 deletions packages/eventindexer/http/get_current_provers.go

This file was deleted.

64 changes: 0 additions & 64 deletions packages/eventindexer/http/get_pos_stats.go

This file was deleted.

50 changes: 0 additions & 50 deletions packages/eventindexer/http/get_pos_stats_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions packages/eventindexer/http/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ func (srv *Server) configureRoutes() {
srv.echo.GET("/eventByAddress", srv.GetCountByAddressAndEventName)
srv.echo.GET("/events", srv.GetByAddressAndEventName)
srv.echo.GET("/stats", srv.GetStats)
srv.echo.GET("/posStats", srv.GetPOSStats)
srv.echo.GET("/currentProvers", srv.GetCurrentProvers)
srv.echo.GET("/assignedBlocks", srv.GetAssignedBlocksByProverAddress)
srv.echo.GET("/nftsByAddress", srv.GetNFTBalancesByAddessAndChainID)

Expand Down
30 changes: 6 additions & 24 deletions packages/eventindexer/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import (
"os"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/labstack/echo/v4/middleware"
"github.com/patrickmn/go-cache"
"github.com/taikoxyz/taiko-mono/packages/eventindexer"
"github.com/taikoxyz/taiko-mono/packages/eventindexer/contracts/proverpool"

echoprom "github.com/labstack/echo-contrib/prometheus"
echo "github.com/labstack/echo/v4"
Expand All @@ -24,17 +22,15 @@ type Server struct {
statRepo eventindexer.StatRepository
nftBalanceRepo eventindexer.NFTBalanceRepository
cache *cache.Cache
proverPool *proverpool.ProverPool
}

type NewServerOpts struct {
Echo *echo.Echo
EventRepo eventindexer.EventRepository
StatRepo eventindexer.StatRepository
NFTBalanceRepo eventindexer.NFTBalanceRepository
ProverPoolAddress common.Address
EthClient *ethclient.Client
CorsOrigins []string
Echo *echo.Echo
EventRepo eventindexer.EventRepository
StatRepo eventindexer.StatRepository
NFTBalanceRepo eventindexer.NFTBalanceRepository
EthClient *ethclient.Client
CorsOrigins []string
}

func (opts NewServerOpts) Validate() error {
Expand All @@ -58,8 +54,6 @@ func (opts NewServerOpts) Validate() error {
return eventindexer.ErrNoNFTBalanceRepository
}

// proverpooladdress is optional

return nil
}

Expand All @@ -70,24 +64,12 @@ func NewServer(opts NewServerOpts) (*Server, error) {

cache := cache.New(5*time.Minute, 10*time.Minute)

var proverPool *proverpool.ProverPool

var err error

if opts.ProverPoolAddress.Hex() != "" {
proverPool, err = proverpool.NewProverPool(opts.ProverPoolAddress, opts.EthClient)
if err != nil {
return nil, err
}
}

srv := &Server{
echo: opts.Echo,
eventRepo: opts.EventRepo,
statRepo: opts.StatRepo,
nftBalanceRepo: opts.NFTBalanceRepo,
cache: cache,
proverPool: proverPool,
}

corsOrigins := opts.CorsOrigins
Expand Down
59 changes: 1 addition & 58 deletions packages/eventindexer/indexer/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func L1FilterFunc(
})

wg.Go(func() error {
blockVerifiedEvents, err := svc.taikol1.FilterBlockVerified(filterOpts, nil)
blockVerifiedEvents, err := svc.taikol1.FilterBlockVerified(filterOpts, nil, nil)
if err != nil {
return errors.Wrap(err, "svc.taikol1.FilterBlockVerified")
}
Expand Down Expand Up @@ -87,63 +87,6 @@ func L1FilterFunc(
})
}

if svc.proverPool != nil {
wg.Go(func() error {
slashedEvents, err := svc.proverPool.FilterSlashed(filterOpts, nil, nil)
if err != nil {
return errors.Wrap(err, "svc.proverPool.FilterSlashed")
}

err = svc.saveSlashedEvents(ctx, chainID, slashedEvents)
if err != nil {
return errors.Wrap(err, "svc.saveSlashedEvents")
}

return nil
})

wg.Go(func() error {
stakedEvents, err := svc.proverPool.FilterStaked(filterOpts, nil)
if err != nil {
return errors.Wrap(err, "svc.proverPool.FilterStaked")
}

err = svc.saveStakedEvents(ctx, chainID, stakedEvents)
if err != nil {
return errors.Wrap(err, "svc.saveStakedEvents")
}

return nil
})

wg.Go(func() error {
exitedEvents, err := svc.proverPool.FilterExited(filterOpts, nil)
if err != nil {
return errors.Wrap(err, "svc.proverPool.FilterExited")
}

err = svc.saveExitedEvents(ctx, chainID, exitedEvents)
if err != nil {
return errors.Wrap(err, "svc.saveExitedEvents")
}

return nil
})

wg.Go(func() error {
withdrawnEvents, err := svc.proverPool.FilterWithdrawn(filterOpts, nil)
if err != nil {
return errors.Wrap(err, "svc.proverPool.FilterWithdrawn")
}

err = svc.saveWithdrawnEvents(ctx, chainID, withdrawnEvents)
if err != nil {
return errors.Wrap(err, "svc.saveWithdrawnEvents")
}
return nil
})
}

if svc.indexNfts {
wg.Go(func() error {
if err := svc.indexNFTTransfers(ctx, chainID, filterOpts.Start, *filterOpts.End); err != nil {
Expand Down
Loading

0 comments on commit 87c9d53

Please sign in to comment.