Skip to content

Commit

Permalink
Comments fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Oct 28, 2022
1 parent 8aa1f52 commit 9b64cc2
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 17 deletions.
10 changes: 8 additions & 2 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type Consensus interface {
// GetSyncProgression retrieves the current sync progression, if any
GetSyncProgression() *progress.Progression

// GenerateExitProof generates exit proof for given exit event id
GenerateExitProof(exitID, epoch, checkpointNumber uint64) ([]types.Hash, error)
// GetBridgeProvider returns an instance of BridgeDataProvider
GetBridgeProvider() BridgeDataProvider

// Initialize initializes the consensus (e.g. setup data)
Initialize() error
Expand Down Expand Up @@ -78,3 +78,9 @@ type Params struct {

// Factory is the factory function to create a discovery consensus
type Factory func(*Params) (Consensus, error)

// BridgeDataProvider is an interface providing bridge related functions
type BridgeDataProvider interface {
// GenerateExit proof generates proof of exit for given exit event
GenerateExitProof(exitID, epoch, checkpointBlock uint64) ([]types.Hash, error)
}
4 changes: 2 additions & 2 deletions consensus/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,6 @@ func (d *Dev) Close() error {
return nil
}

func (d *Dev) GenerateExitProof(exitID, epoch, checkpointBlock uint64) ([]types.Hash, error) {
return nil, nil
func (d *Dev) GetBridgeProvider() consensus.BridgeDataProvider {
return nil
}
4 changes: 2 additions & 2 deletions consensus/dummy/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (d *Dummy) Close() error {
return nil
}

func (d *Dummy) GenerateExitProof(exitID, epoch, checkpointBlock uint64) ([]types.Hash, error) {
return nil, nil
func (d *Dummy) GetBridgeProvider() consensus.BridgeDataProvider {
return nil
}

func (d *Dummy) run() {
Expand Down
5 changes: 3 additions & 2 deletions consensus/ibft/ibft.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,9 @@ func (i *backendIBFT) SetHeaderHash() {
}
}

func (i *backendIBFT) GenerateExitProof(exitID, epoch, checkpointBlock uint64) ([]types.Hash, error) {
return nil, nil
// GetBridgeProvider returns an instance of BridgeDataProvider
func (i *backendIBFT) GetBridgeProvider() consensus.BridgeDataProvider {
return nil
}

// updateCurrentModules updates Signer, Hooks, and Validators
Expand Down
4 changes: 2 additions & 2 deletions consensus/polybft/consensus_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,8 @@ func (c *consensusRuntime) getExitEventRootHash(epoch uint64) (types.Hash, error
return tree.Hash(), nil
}

// generateExitProof generates proof of exit
func (c *consensusRuntime) generateExitProof(exitID, epoch, checkpointBlock uint64) ([]types.Hash, error) {
// GenerateExitProof generates proof of exit
func (c *consensusRuntime) GenerateExitProof(exitID, epoch, checkpointBlock uint64) ([]types.Hash, error) {
exitEvent, err := c.state.getExitEvent(exitID, epoch, checkpointBlock)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions consensus/polybft/consensus_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ func TestConsensusRuntime_getExitEventRootHash(t *testing.T) {
})
}

func TestConsensusRuntime_generateExitProof(t *testing.T) {
func TestConsensusRuntime_GenerateExitProof(t *testing.T) {
const (
numOfBlocks = 10
numOfEventsPerBlock = 2
Expand All @@ -1689,7 +1689,7 @@ func TestConsensusRuntime_generateExitProof(t *testing.T) {
tree, err := NewMerkleTree(checkpointEvents)
require.NoError(t, err)

proof, err := runtime.generateExitProof(1, 1, 1)
proof, err := runtime.GenerateExitProof(1, 1, 1)
require.NoError(t, err)
require.NotNil(t, proof)

Expand All @@ -1707,7 +1707,7 @@ func TestConsensusRuntime_generateExitProof(t *testing.T) {
})

t.Run("Generate exit proof - no event", func(t *testing.T) {
_, err := runtime.generateExitProof(21, 1, 1)
_, err := runtime.GenerateExitProof(21, 1, 1)
require.ErrorContains(t, err, "could not find any exit event that has an id")
})
}
Expand Down
6 changes: 3 additions & 3 deletions consensus/polybft/polybft.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,9 @@ func (p *Polybft) PreCommitState(_ *types.Header, _ *state.Transition) error {
return nil
}

// GenerateExitProof generates proof for given exit event
func (p *Polybft) GenerateExitProof(exitID, epoch, checkpointBlock uint64) ([]types.Hash, error) {
return p.runtime.generateExitProof(exitID, epoch, checkpointBlock)
// GetBridgeProvider returns an instance of BridgeDataProvider
func (p *Polybft) GetBridgeProvider() consensus.BridgeDataProvider {
return p.runtime
}

type pbftTransportWrapper struct {
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/bridge_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ type Bridge struct {
}

// GenerateExitProof generates exit proof for given exit event
func (b *Bridge) GenerateExitProof(exitID, epoch, checkpointBlock BlockNumber) (interface{}, error) {
func (b *Bridge) GenerateExitProof(exitID, epoch, checkpointBlock argUint64) (interface{}, error) {
return b.store.GenerateExitProof(uint64(exitID), uint64(epoch), uint64(checkpointBlock))
}
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ type jsonRPCHub struct {
*state.Executor
*network.Server
consensus.Consensus
consensus.BridgeDataProvider
}

// HELPER + WRAPPER METHODS //
Expand Down Expand Up @@ -563,6 +564,7 @@ func (s *Server) setupJSONRPC() error {
Executor: s.executor,
Consensus: s.consensus,
Server: s.network,
BridgeDataProvider: s.consensus.GetBridgeProvider(),
}

conf := &jsonrpc.Config{
Expand Down

0 comments on commit 9b64cc2

Please sign in to comment.