Skip to content

Commit

Permalink
Merge pull request #45 from EspressoSystems/jh/fix
Browse files Browse the repository at this point in the history
Fix isHotShotLive
  • Loading branch information
ImJeremyHe authored Jul 2, 2024
2 parents 8daf0d4 + 1140a03 commit f7eeae6
Show file tree
Hide file tree
Showing 5 changed files with 2,451 additions and 2 deletions.
2 changes: 1 addition & 1 deletion espresso-sequencer
2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ bind-hotshot:
bind-light-client:
cd espresso-sequencer/contracts && forge build --force
cd espresso-sequencer/contracts/out/LightClient.sol && cat LightClient.json | jq .abi > LightClient.abi
cd espresso-sequencer/contracts/out/LightClientMock.sol && cat LightClientMock.json | jq .abi > LightClientMock.abi
abigen --abi espresso-sequencer/contracts/out/LightClient.sol/LightClient.abi --pkg lightclient --out light-client/lightclient.go
abigen --abi espresso-sequencer/contracts/out/LightClientMock.sol/LightClientMock.abi --pkg lightclientmock --out light-client-mock/lightclient.go
2,384 changes: 2,384 additions & 0 deletions light-client-mock/lightclient.go

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions light-client-mock/test_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This file contains functions that help people interact with light client mock contract.
package lightclientmock

import (
"context"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
)

func FreezeL1Height(t *testing.T, client bind.ContractBackend, contractAddress common.Address, txOpts *bind.TransactOpts) error {
mockLightClient, err := NewLightclientmock(contractAddress, client)
if err != nil {
return err
}

header, err := client.HeaderByNumber(context.Background(), nil)
if err != nil {
return err
}

_, err = mockLightClient.SetHotShotDownSince(txOpts, header.Number)
if err != nil {
return err
}

return nil
}

func UnfreezeL1Height(t *testing.T, client bind.ContractBackend, contractAddress common.Address, txOpts *bind.TransactOpts) error {
mockLightClient, err := NewLightclientmock(contractAddress, client)
if err != nil {
return err
}
_, err = mockLightClient.SetHotShotUp(txOpts)

return err
}

func IsHotShotLive(t *testing.T, client bind.ContractBackend, contractAddress common.Address, threshold uint64) (bool, error) {
mockLightClient, err := NewLightclientmock(contractAddress, client)
if err != nil {
return false, err
}

header, err := client.HeaderByNumber(context.Background(), nil)
if err != nil {
return false, err
}

isDown, err := mockLightClient.LagOverEscapeHatchThreshold(nil, header.Number, new(big.Int).SetUint64(threshold))
if err != nil {
return false, err
}

return !isDown, nil
}
6 changes: 5 additions & 1 deletion light-client/light_client_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,9 @@ func (l *LightClientReader) IsHotShotLive(delayThreshold uint64) (bool, error) {
return false, err
}
threshold := new(big.Int).SetUint64(delayThreshold)
return l.LightClient.LagOverEscapeHatchThreshold(&bind.CallOpts{}, header.Number, threshold)
isDown, err := l.LightClient.LagOverEscapeHatchThreshold(&bind.CallOpts{}, header.Number, threshold)
if err != nil {
return false, err
}
return !isDown, nil
}

0 comments on commit f7eeae6

Please sign in to comment.