@@ -11,16 +11,12 @@ import (
1111 "time"
1212
1313 "github.com/ethereum/go-ethereum"
14- "github.com/ethereum/go-ethereum/accounts/abi/bind"
15- "github.com/ethereum/go-ethereum/common"
1614 "github.com/ethereum/go-ethereum/core/types"
1715 "github.com/ethereum/go-ethereum/ethclient"
1816 "github.com/ethereum/go-ethereum/rpc"
1917
2018 . "github.com/cartesi/rollups-node/internal/model"
2119 "github.com/cartesi/rollups-node/internal/repository"
22- "github.com/cartesi/rollups-node/pkg/contracts/iapplication"
23- "github.com/cartesi/rollups-node/pkg/contracts/iinputbox"
2420 "github.com/cartesi/rollups-node/pkg/ethutil"
2521)
2622
@@ -40,6 +36,7 @@ type EvmReaderRepository interface {
4036 ) error
4137 GetEpoch (ctx context.Context , nameOrAddress string , index uint64 ) (* Epoch , error )
4238 ListEpochs (ctx context.Context , nameOrAddress string , f repository.EpochFilter , p repository.Pagination , descending bool ) ([]* Epoch , uint64 , error )
39+ UpdateEpoch (ctx context.Context , nameOrAddress string , e * Epoch ) error
4340
4441 // Output execution monitor
4542 GetOutput (ctx context.Context , nameOrAddress string , indexKey uint64 ) (* Output , error )
@@ -53,22 +50,6 @@ type EthClientInterface interface {
5350 ChainID (ctx context.Context ) (* big.Int , error )
5451}
5552
56- type ApplicationContractAdapter interface {
57- RetrieveOutputExecutionEvents (
58- opts * bind.FilterOpts ,
59- ) ([]* iapplication.IApplicationOutputExecuted , error )
60- GetDeploymentBlockNumber (opts * bind.CallOpts ) (* big.Int , error )
61- }
62-
63- // Interface for Input reading
64- type InputSourceAdapter interface {
65- // Wrapper for FilterInputAdded(), which is automatically generated
66- // by go-ethereum and cannot be used for testing
67- RetrieveInputs (opts * bind.FilterOpts , appAddresses []common.Address , index []* big.Int ,
68- ) ([]iinputbox.IInputBoxInputAdded , error )
69- GetNumberOfInputs (opts * bind.CallOpts , appContract common.Address ) (* big.Int , error )
70- }
71-
7253type SubscriptionError struct {
7354 Cause error
7455}
@@ -82,6 +63,7 @@ type appContracts struct {
8263 application * Application
8364 applicationContract ApplicationContractAdapter
8465 inputSource InputSourceAdapter
66+ daveConsensus DaveConsensusAdapter
8567}
8668
8769func (r * Service ) Run (ctx context.Context , ready chan struct {}) error {
@@ -151,8 +133,10 @@ func (r *Service) watchForNewBlocks(ctx context.Context, ready chan<- struct{})
151133
152134 // Build Contracts
153135 var apps []appContracts
136+ var daveConsensusApps []appContracts
137+ var iconsensusApps []appContracts
154138 for _ , app := range runningApps {
155- applicationContract , inputSource , err := r .adapterFactory .CreateAdapters (app , r .client )
139+ applicationContract , inputSource , daveConsensus , err := r .adapterFactory .CreateAdapters (app , r .client )
156140
157141 if err != nil {
158142 r .Logger .Error ("Error retrieving application contracts" , "app" , app , "error" , err )
@@ -162,9 +146,15 @@ func (r *Service) watchForNewBlocks(ctx context.Context, ready chan<- struct{})
162146 application : app ,
163147 applicationContract : applicationContract ,
164148 inputSource : inputSource ,
149+ daveConsensus : daveConsensus ,
165150 }
166151
167152 apps = append (apps , aContracts )
153+ if app .DaveConsensus {
154+ daveConsensusApps = append (daveConsensusApps , aContracts )
155+ } else {
156+ iconsensusApps = append (iconsensusApps , aContracts )
157+ }
168158 }
169159
170160 if len (apps ) == 0 {
@@ -190,7 +180,9 @@ func (r *Service) watchForNewBlocks(ctx context.Context, ready chan<- struct{})
190180 mostRecentHeader .Number .Uint64 (), header .Number .Uint64 (), r .defaultBlock ))
191181 }
192182
193- r .checkForNewInputs (ctx , apps , blockNumber )
183+ r .checkForEpochsAndInputs (ctx , daveConsensusApps , blockNumber )
184+
185+ r .checkForNewInputs (ctx , iconsensusApps , blockNumber )
194186
195187 r .checkForOutputExecution (ctx , apps , blockNumber )
196188
@@ -234,39 +226,50 @@ func (r *Service) fetchMostRecentHeader(
234226}
235227
236228type AdapterFactory interface {
237- CreateAdapters (app * Application , client EthClientInterface ) (ApplicationContractAdapter , InputSourceAdapter , error )
229+ CreateAdapters (app * Application , client EthClientInterface ) (ApplicationContractAdapter , InputSourceAdapter , DaveConsensusAdapter , error )
238230}
239231
240232type DefaultAdapterFactory struct {
241233 Filter ethutil.Filter
242234}
243235
244- func (f * DefaultAdapterFactory ) CreateAdapters (app * Application , client EthClientInterface ) (ApplicationContractAdapter , InputSourceAdapter , error ) {
236+ func (f * DefaultAdapterFactory ) CreateAdapters (app * Application , client EthClientInterface ) (ApplicationContractAdapter , InputSourceAdapter , DaveConsensusAdapter , error ) {
245237 if app == nil {
246- return nil , nil , fmt .Errorf ("Application reference is nil. Should never happen" )
238+ return nil , nil , nil , fmt .Errorf ("Application reference is nil. Should never happen" )
247239 }
248240
249241 // Type assertion to get the concrete client if possible
250242 ethClient , ok := client .(* ethclient.Client )
251243 if ! ok {
252- return nil , nil , fmt .Errorf ("client is not an *ethclient.Client, cannot create adapters" )
244+ return nil , nil , nil , fmt .Errorf ("client is not an *ethclient.Client, cannot create adapters" )
253245 }
254246
255247 applicationContract , err := NewApplicationContractAdapter (app .IApplicationAddress , ethClient , f .Filter )
256248 if err != nil {
257- return nil , nil , errors .Join (
249+ return nil , nil , nil , errors .Join (
258250 fmt .Errorf ("error building application contract" ),
259251 err ,
260252 )
261253 }
262254
263255 inputSource , err := NewInputSourceAdapter (app .IInputBoxAddress , ethClient , f .Filter )
264256 if err != nil {
265- return nil , nil , errors .Join (
257+ return nil , nil , nil , errors .Join (
266258 fmt .Errorf ("error building inputbox contract" ),
267259 err ,
268260 )
269261 }
270262
271- return applicationContract , inputSource , nil
263+ var daveConsensus DaveConsensusAdapter
264+ if app .DaveConsensus {
265+ daveConsensus , err = NewDaveConsensusAdapter (app .IConsensusAddress , ethClient , f .Filter )
266+ if err != nil {
267+ return nil , nil , nil , errors .Join (
268+ fmt .Errorf ("error building daveconsensus contract" ),
269+ err ,
270+ )
271+ }
272+ }
273+
274+ return applicationContract , inputSource , daveConsensus , nil
272275}
0 commit comments