-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(f3): resolve finality for eth APIs according to F3
- Loading branch information
Showing
13 changed files
with
858 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package lf3 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/filecoin-project/go-f3/certs" | ||
"github.com/filecoin-project/go-f3/gpbft" | ||
"github.com/filecoin-project/go-f3/manifest" | ||
|
||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
) | ||
|
||
type DisabledF3 struct{} | ||
|
||
var _ F3API = DisabledF3{} | ||
|
||
func (DisabledF3) GetOrRenewParticipationTicket(_ context.Context, _ uint64, _ api.F3ParticipationTicket, _ uint64) (api.F3ParticipationTicket, error) { | ||
return api.F3ParticipationTicket{}, api.ErrF3Disabled | ||
} | ||
func (DisabledF3) Participate(_ context.Context, _ api.F3ParticipationTicket) (api.F3ParticipationLease, error) { | ||
return api.F3ParticipationLease{}, api.ErrF3Disabled | ||
} | ||
func (DisabledF3) GetCert(_ context.Context, _ uint64) (*certs.FinalityCertificate, error) { | ||
return nil, api.ErrF3Disabled | ||
} | ||
func (DisabledF3) GetLatestCert(_ context.Context) (*certs.FinalityCertificate, error) { | ||
return nil, api.ErrF3Disabled | ||
} | ||
func (DisabledF3) GetManifest(_ context.Context) (*manifest.Manifest, error) { | ||
return nil, api.ErrF3Disabled | ||
} | ||
func (DisabledF3) GetPowerTable(_ context.Context, _ types.TipSetKey) (gpbft.PowerEntries, error) { | ||
return nil, api.ErrF3Disabled | ||
} | ||
func (DisabledF3) GetF3PowerTable(_ context.Context, _ types.TipSetKey) (gpbft.PowerEntries, error) { | ||
return nil, api.ErrF3Disabled | ||
} | ||
func (DisabledF3) IsEnabled() bool { return false } | ||
func (DisabledF3) IsRunning() (bool, error) { return false, api.ErrF3Disabled } | ||
func (DisabledF3) Progress() (gpbft.Instant, error) { return gpbft.Instant{}, api.ErrF3Disabled } | ||
func (DisabledF3) ListParticipants() ([]api.F3Participant, error) { return nil, api.ErrF3Disabled } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/go-f3/certs" | ||
"github.com/filecoin-project/go-f3/gpbft" | ||
"github.com/filecoin-project/go-f3/manifest" | ||
|
||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/chain/lf3" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
) | ||
|
||
type MockF3API struct { | ||
lk sync.Mutex | ||
|
||
latestCert *certs.FinalityCertificate | ||
manifest *manifest.Manifest | ||
enabled bool | ||
running bool | ||
} | ||
|
||
func (m *MockF3API) GetOrRenewParticipationTicket(ctx context.Context, minerID uint64, previous api.F3ParticipationTicket, instances uint64) (api.F3ParticipationTicket, error) { | ||
if !m.IsEnabled() { | ||
return api.F3ParticipationTicket{}, api.ErrF3Disabled | ||
} | ||
return api.F3ParticipationTicket{}, nil | ||
} | ||
|
||
func (m *MockF3API) Participate(ctx context.Context, ticket api.F3ParticipationTicket) (api.F3ParticipationLease, error) { | ||
if !m.IsEnabled() { | ||
return api.F3ParticipationLease{}, api.ErrF3Disabled | ||
} | ||
return api.F3ParticipationLease{}, nil | ||
} | ||
|
||
func (m *MockF3API) GetCert(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error) { | ||
if !m.IsEnabled() { | ||
return nil, api.ErrF3Disabled | ||
} | ||
return nil, nil | ||
} | ||
|
||
// SetLatestCert sets the latest certificate to be returned by GetLatestCert. If GetLatestCert is | ||
// called before this method, it will return an error. | ||
func (m *MockF3API) SetLatestCert(cert *certs.FinalityCertificate) { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
m.latestCert = cert | ||
} | ||
|
||
func (m *MockF3API) GetLatestCert(ctx context.Context) (*certs.FinalityCertificate, error) { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
if !m.enabled { | ||
return nil, api.ErrF3Disabled | ||
} | ||
|
||
if m.latestCert == nil { | ||
return nil, xerrors.Errorf("no latest cert set in test, did you mean to?") | ||
} | ||
|
||
return m.latestCert, nil | ||
} | ||
|
||
// SetManifest sets the manifest to be returned by GetManifest. If GetManifest is called before this | ||
// method, it will return an error. | ||
// | ||
// Use manifest.LocalDevnetManifest() for a convenient manifest to use in tests. | ||
func (m *MockF3API) SetManifest(manifest *manifest.Manifest) { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
m.manifest = manifest | ||
} | ||
|
||
func (m *MockF3API) GetManifest(ctx context.Context) (*manifest.Manifest, error) { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
if !m.enabled { | ||
return nil, api.ErrF3Disabled | ||
} | ||
|
||
if m.manifest == nil { | ||
return nil, xerrors.Errorf("no manifest set in test, did you mean to?") | ||
} | ||
|
||
return m.manifest, nil | ||
} | ||
|
||
func (m *MockF3API) GetPowerTable(ctx context.Context, tsk types.TipSetKey) (gpbft.PowerEntries, error) { | ||
if !m.IsEnabled() { | ||
return nil, api.ErrF3Disabled | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func (m *MockF3API) GetF3PowerTable(ctx context.Context, tsk types.TipSetKey) (gpbft.PowerEntries, error) { | ||
if !m.IsEnabled() { | ||
return nil, api.ErrF3Disabled | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func (m *MockF3API) SetEnabled(enabled bool) { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
m.enabled = enabled | ||
} | ||
|
||
func (m *MockF3API) IsEnabled() bool { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
return m.enabled | ||
} | ||
|
||
func (m *MockF3API) SetRunning(running bool) { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
m.running = running | ||
} | ||
|
||
func (m *MockF3API) IsRunning() (bool, error) { | ||
m.lk.Lock() | ||
defer m.lk.Unlock() | ||
|
||
if !m.enabled { | ||
return false, api.ErrF3Disabled | ||
} | ||
|
||
return m.running, nil | ||
} | ||
|
||
func (m *MockF3API) Progress() (gpbft.Instant, error) { | ||
if !m.IsEnabled() { | ||
return gpbft.Instant{}, api.ErrF3Disabled | ||
} | ||
|
||
return gpbft.Instant{}, nil | ||
} | ||
|
||
func (m *MockF3API) ListParticipants() ([]api.F3Participant, error) { | ||
if !m.IsEnabled() { | ||
return nil, api.ErrF3Disabled | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
var _ lf3.F3API = (*MockF3API)(nil) |
Oops, something went wrong.