Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shed): gas-sim compact-sectors #12837

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions chain/beacon/drand/drand.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
}
hc.(DrandHTTPClient).SetUserAgent("drand-client-lotus/" + build.NodeBuildVersion)
clients = append(clients, hc)

}

opts := []dclient.Option{
Expand All @@ -113,6 +112,18 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
opts = append(opts, gclient.WithPubsub(ps))
} else {
log.Info("drand beacon without pubsub")
if len(clients) == 0 {
// This hack is necessary to convince a drand beacon to start without any clients. For
// historical becaons we need them to be able to verify old entries but we don't need to fetch
// new ones. With pubsub enabled, it acts as a client so drand is happy, but if we don't have
// pubsub then drand will complain about old beacons withotu clients. So we make one that
// it'll think is a valid client and that it won't speed test (hence the need to mark it as
// as "watcher").
historicalClient := &historicalBeaconClient{}
opts = append(opts, dclient.WithWatcher(func(chainInfo *dchain.Info, cache dclient.Cache) (dclient.Watcher, error) {
return historicalClient, nil
}))
}
}

client, err := dclient.Wrap(clients, opts...)
Expand Down Expand Up @@ -239,13 +250,41 @@ var _ beacon.RandomBeacon = (*DrandBeacon)(nil)

func BeaconScheduleFromDrandSchedule(dcs dtypes.DrandSchedule, genesisTime uint64, ps *pubsub.PubSub) (beacon.Schedule, error) {
shd := beacon.Schedule{}
for _, dc := range dcs {
for i, dc := range dcs {
bc, err := NewDrandBeacon(genesisTime, buildconstants.BlockDelaySecs, ps, dc.Config)
if err != nil {
return nil, xerrors.Errorf("creating drand beacon: %w", err)
return nil, xerrors.Errorf("%d creating drand beacon: %w", i, err)
}
shd = append(shd, beacon.BeaconPoint{Start: dc.Start, Beacon: bc})
}

return shd, nil
}

var _ dclient.Client = historicalBeaconClient{}

// historicalBeaconClient is a drand client that doesn't actually do anything. It's used when
// we don't have a drand network to connect to but still need to provide a beacon client.
// We don't expect calls through to the client to be made since we should only be verifying old
// randomness, not fetching it.
type historicalBeaconClient struct{}

func (h historicalBeaconClient) Get(ctx context.Context, round uint64) (dclient.Result, error) {
return nil, xerrors.Errorf("no historical randomness available")
}

func (h historicalBeaconClient) Watch(ctx context.Context) <-chan dclient.Result {
return nil
}

func (h historicalBeaconClient) Info(ctx context.Context) (*dchain.Info, error) {
return nil, xerrors.Errorf("no historical randomness available")
}

func (h historicalBeaconClient) RoundAt(time.Time) uint64 {
return 0
}

func (h historicalBeaconClient) Close() error {
return nil
}
16 changes: 11 additions & 5 deletions chain/stmgr/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
type execMessageStrategy int

const (
execNoMessages execMessageStrategy = iota // apply no prior or current tipset messages
execNoMessages execMessageStrategy = iota // apply no prior or current tipset messages unless supplied
execAllMessages // apply all prior and current tipset messages
execSameSenderMessages // apply all prior messages and any current tipset messages from the same sender
)
Expand Down Expand Up @@ -60,8 +60,8 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.
}

// ApplyOnStateWithGas applies the given message on top of the given state root with gas tracing enabled
func (sm *StateManager) ApplyOnStateWithGas(ctx context.Context, stateCid cid.Cid, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error) {
return sm.callInternal(ctx, msg, nil, ts, stateCid, sm.GetNetworkVersion, true, execNoMessages)
func (sm *StateManager) ApplyOnStateWithGas(ctx context.Context, stateCid cid.Cid, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet) (*api.InvocResult, error) {
return sm.callInternal(ctx, msg, priorMsgs, ts, stateCid, sm.GetNetworkVersion, true, execNoMessages)
}

// CallWithGas calculates the state for a given tipset, and then applies the given message on top of that state.
Expand Down Expand Up @@ -174,7 +174,7 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr

switch strategy {
case execNoMessages:
// Do nothing
// Do nothing, unless we have prior messages to apply
case execAllMessages, execSameSenderMessages:
tsMsgs, err := sm.cs.MessagesForTipset(ctx, ts)
if err != nil {
Expand All @@ -190,13 +190,19 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
filteredTsMsgs = append(filteredTsMsgs, tsMsg)
}
}
log.Debugf("applying %d additional messages from same sender", len(filteredTsMsgs))
priorMsgs = append(filteredTsMsgs, priorMsgs...)
}
}

if len(priorMsgs) > 0 {
for i, m := range priorMsgs {
_, err = vmi.ApplyMessage(ctx, m)
ret, err := vmi.ApplyMessage(ctx, m)
if err != nil {
return nil, xerrors.Errorf("applying prior message (%d, %s): %w", i, m.Cid(), err)
}
// TODO: return this information to the caller
log.Debugf("applied prior message %s: %d [%x]: %s", m.Cid(), ret.MessageReceipt.ExitCode, ret.MessageReceipt.Return, ret.ActorErr)
}

// We flush to get the VM's view of the state tree after applying the above messages
Expand Down
Loading
Loading