-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
Signed-off-by: Jakub Sztandera <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package lf3 | ||
|
||
import ( | ||
"context" | ||
"sort" | ||
"time" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-f3" | ||
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Build
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-fevm)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-fevm)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Check (gen-check)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-deadlines)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-deadlines)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-migration)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_block_hash)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_block_hash)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-splitstore)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-splitstore)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (unit-rest)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (unit-rest)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_terminate)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_terminate)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_terminate)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost_dispute)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost_dispute)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_legacy_transactions)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_legacy_transactions)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-paych_api)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-paych_api)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_filter)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_filter)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost_config)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost_config)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost_no_miner_storage)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost_no_miner_storage)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-supply)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-supply)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (unit-cli)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (unit-cli)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost_worker_config)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost_worker_config)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sealing_resources)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sealing_resources)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_unseal)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_hash_lookup)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_hash_lookup)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-direct_data_onboard_verified)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-direct_data_onboard_verified)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-harmonydb)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-harmonydb)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-api)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-api)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-direct_data_onboard)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-direct_data_onboard)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-gateway)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-gateway)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_pledge)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_pledge)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-worker)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-worker)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_import_full)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_import_full)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_import_simple)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_import_simple)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-deals_invalid_utf8_label)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-deals_invalid_utf8_label)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-dup_mpool_messages)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-dup_mpool_messages)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-wdpost)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_account_abstraction)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_account_abstraction)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_api)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_api)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_config)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_config)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_bytecode)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_conformance)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_conformance)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_balance)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_balance)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_deploy)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_deploy)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_fee_history)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_fee_history)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_transactions)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-eth_transactions)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-gas_estimation)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-gas_estimation)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-fevm_events)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-fevm_events)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-get_messages_in_ts)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-get_messages_in_ts)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-lite_migration)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-lite_migration)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-fevm_address)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-fevm_address)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-mempool)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-mempool)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-lookup_robust_address)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-lookup_robust_address)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-mpool_msg_uuid)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-mpool_msg_uuid)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-mpool_push_with_uuid)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-mpool_push_with_uuid)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-manual_onboarding)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-manual_onboarding)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-msgindex)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-msgindex)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-multisig)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-multisig)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-nonce)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-nonce)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-pending_deal_allocation)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-pending_deal_allocation)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-remove_verifreg_datacap)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-remove_verifreg_datacap)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-net)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-net)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_miner_collateral)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_miner_collateral)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_numassign)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-sector_numassign)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-path_detach_redeclare)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-path_detach_redeclare)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-self_sent_txn)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-self_sent_txn)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-verifreg)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (itest-verifreg)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (unit-node)
Check failure on line 9 in chain/lf3/ec.go GitHub Actions / Test (unit-node)
|
||
"github.com/filecoin-project/go-f3/gpbft" | ||
Check failure on line 10 in chain/lf3/ec.go GitHub Actions / Test (unit-rest)
Check failure on line 10 in chain/lf3/ec.go GitHub Actions / Test (unit-rest)
Check failure on line 10 in chain/lf3/ec.go GitHub Actions / Test (unit-node)
Check failure on line 10 in chain/lf3/ec.go GitHub Actions / Test (unit-node)
|
||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/big" | ||
"github.com/filecoin-project/lotus/chain/actors/builtin/power" | ||
"github.com/filecoin-project/lotus/chain/stmgr" | ||
"github.com/filecoin-project/lotus/chain/store" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
type ecWrapper struct { | ||
ChainStore *store.ChainStore | ||
StateManager *stmgr.StateManager | ||
Manifest f3.Manifest | ||
} | ||
|
||
type tsWrapper struct { | ||
inner *types.TipSet | ||
} | ||
|
||
func (ts *tsWrapper) Key() gpbft.TipSetKey { | ||
return ts.inner.Key().Bytes() | ||
} | ||
|
||
func (ts *tsWrapper) Beacon() []byte { | ||
// TOOD: verify if correct | ||
return ts.inner.MinTicket().VRFProof | ||
} | ||
|
||
func (ts *tsWrapper) Epoch() int64 { | ||
return int64(ts.inner.Height()) | ||
} | ||
|
||
func (ts *tsWrapper) Timestamp() time.Time { | ||
return time.Unix(int64(ts.inner.Blocks()[0].Timestamp), 0) | ||
} | ||
|
||
func wrapTS(ts *types.TipSet) f3.TipSet { | ||
if ts == nil { | ||
return nil | ||
} | ||
return &tsWrapper{ts} | ||
} | ||
|
||
// GetTipsetByEpoch should return a tipset before the one requested if the requested | ||
// tipset does not exist due to null epochs | ||
func (ec *ecWrapper) GetTipsetByEpoch(ctx context.Context, epoch int64) (f3.TipSet, error) { | ||
ts, err := ec.ChainStore.GetTipsetByHeight(ctx, abi.ChainEpoch(epoch), nil, true) | ||
if err != nil { | ||
return nil, xerrors.Errorf("getting tipset by height: %w", err) | ||
} | ||
return wrapTS(ts), nil | ||
} | ||
|
||
func (ec *ecWrapper) GetTipset(ctx context.Context, tsk gpbft.TipSetKey) (f3.TipSet, error) { | ||
tskLotus, err := types.TipSetKeyFromBytes([]byte(tsk)) | ||
if err != nil { | ||
return nil, xerrors.Errorf("decoding tsk: %w", err) | ||
} | ||
|
||
ts, err := ec.ChainStore.GetTipSetFromKey(ctx, tskLotus) | ||
if err != nil { | ||
return nil, xerrors.Errorf("getting tipset by key: %w", err) | ||
} | ||
|
||
return wrapTS(ts), nil | ||
} | ||
|
||
func (ec *ecWrapper) GetHead(_ context.Context) (f3.TipSet, error) { | ||
return wrapTS(ec.ChainStore.GetHeaviestTipSet()), nil | ||
} | ||
|
||
func (ec *ecWrapper) GetParent(ctx context.Context, tsF3 f3.TipSet) (f3.TipSet, error) { | ||
var ts *types.TipSet | ||
if tsW, ok := tsF3.(*tsWrapper); ok { | ||
ts = tsW.inner | ||
} else { | ||
tskLotus, err := types.TipSetKeyFromBytes([]byte(tsF3.Key())) | ||
if err != nil { | ||
return nil, xerrors.Errorf("decoding tsk: %w", err) | ||
} | ||
ts, err = ec.ChainStore.GetTipSetFromKey(ctx, tskLotus) | ||
if err != nil { | ||
return nil, xerrors.Errorf("getting tipset by key for get parent: %w", err) | ||
} | ||
} | ||
parentTs, err := ec.ChainStore.GetTipSetFromKey(ctx, ts.Parents()) | ||
if err != nil { | ||
return nil, xerrors.Errorf("getting parent tipset: %w", err) | ||
} | ||
return wrapTS(parentTs), nil | ||
} | ||
|
||
func (ec *ecWrapper) GetPowerTable(ctx context.Context, tskF3 gpbft.TipSetKey) (gpbft.PowerEntries, error) { | ||
tskLotus, err := types.TipSetKeyFromBytes([]byte(tskF3)) | ||
if err != nil { | ||
return nil, xerrors.Errorf("decoding tsk: %w", err) | ||
} | ||
ts, err := ec.ChainStore.GetTipSetFromKey(ctx, tskLotus) | ||
if err != nil { | ||
return nil, xerrors.Errorf("getting tipset by key for get parent: %w", err) | ||
} | ||
log.Infof("collecting power table for: %d", ts.Height()) | ||
stCid := ts.ParentState() | ||
|
||
sm := ec.StateManager | ||
|
||
powerAct, err := sm.LoadActor(ctx, power.Address, ts) | ||
powerState, err := power.Load(ec.ChainStore.ActorStore(ctx), powerAct) | ||
|
||
var powerEntries gpbft.PowerEntries | ||
err = powerState.ForEachClaim(func(miner address.Address, claim power.Claim) error { | ||
if claim.QualityAdjPower.LessThanEqual(big.Zero()) { | ||
return nil | ||
} | ||
|
||
// TODO: optimize | ||
ok, err := powerState.MinerNominalPowerMeetsConsensusMinimum(miner) | ||
if err != nil { | ||
return xerrors.Errorf("checking consensus minimums: %w", err) | ||
} | ||
if !ok { | ||
return nil | ||
} | ||
|
||
id, err := address.IDFromAddress(miner) | ||
if err != nil { | ||
return xerrors.Errorf("transforming address to ID: %w", err) | ||
} | ||
|
||
pe := gpbft.PowerEntry{ | ||
ID: gpbft.ActorID(id), | ||
Power: claim.QualityAdjPower.Int, | ||
} | ||
waddr, err := stmgr.GetMinerWorkerRaw(ctx, sm, stCid, miner) | ||
if err != nil { | ||
return xerrors.Errorf("GetMinerWorkerRaw failed: %w", err) | ||
} | ||
if waddr.Protocol() != address.BLS { | ||
return xerrors.Errorf("wrong type of worker address") | ||
} | ||
pe.PubKey = gpbft.PubKey(waddr.Payload()) | ||
powerEntries = append(powerEntries, pe) | ||
return nil | ||
}) | ||
if err != nil { | ||
return nil, xerrors.Errorf("collecting the power table: %w", err) | ||
} | ||
|
||
sort.Sort(powerEntries) | ||
return powerEntries, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package lf3 | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/filecoin-project/go-f3" | ||
"github.com/filecoin-project/go-f3/blssig" | ||
Check failure on line 8 in chain/lf3/f3.go GitHub Actions / Build
Check failure on line 8 in chain/lf3/f3.go GitHub Actions / Check (gen-check)
Check failure on line 8 in chain/lf3/f3.go GitHub Actions / Test (unit-rest)
Check failure on line 8 in chain/lf3/f3.go GitHub Actions / Test (unit-rest)
Check failure on line 8 in chain/lf3/f3.go GitHub Actions / Test (unit-cli)
Check failure on line 8 in chain/lf3/f3.go GitHub Actions / Test (unit-cli)
Check failure on line 8 in chain/lf3/f3.go GitHub Actions / Test (unit-node)
Check failure on line 8 in chain/lf3/f3.go GitHub Actions / Test (unit-node)
|
||
"github.com/filecoin-project/go-f3/gpbft" | ||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/build" | ||
"github.com/filecoin-project/lotus/chain/stmgr" | ||
"github.com/filecoin-project/lotus/chain/store" | ||
"github.com/filecoin-project/lotus/node/modules/dtypes" | ||
"github.com/ipfs/go-datastore" | ||
"github.com/ipfs/go-datastore/namespace" | ||
logging "github.com/ipfs/go-log/v2" | ||
pubsub "github.com/libp2p/go-libp2p-pubsub" | ||
"github.com/libp2p/go-libp2p/core/host" | ||
"go.uber.org/fx" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
type F3 struct { | ||
f3 *f3.F3 | ||
} | ||
|
||
type F3Params struct { | ||
fx.In | ||
|
||
NetworkName dtypes.NetworkName | ||
PubSub *pubsub.PubSub | ||
Host host.Host | ||
ChainStore *store.ChainStore | ||
StateManager *stmgr.StateManager | ||
Datastore dtypes.MetadataDS | ||
Wallet api.Wallet | ||
} | ||
|
||
var log = logging.Logger("f3") | ||
|
||
func New(lc fx.Lifecycle, params F3Params) (*F3, error) { | ||
logging.SetLogLevel("f3", "DEBUG") | ||
manifest := f3.LocalnetManifest() | ||
manifest.NetworkName = gpbft.NetworkName(params.NetworkName) | ||
manifest.ECDelay = time.Duration(build.BlockDelaySecs) * time.Second | ||
manifest.ECPeriod = manifest.ECDelay | ||
manifest.BootstrapEpoch = 210 | ||
manifest.ECFinality = 200 | ||
ds := namespace.Wrap(params.Datastore, datastore.NewKey("/f3")) | ||
ec := &ecWrapper{ | ||
ChainStore: params.ChainStore, | ||
StateManager: params.StateManager, | ||
Manifest: manifest, | ||
} | ||
verif := blssig.VerifierWithKeyOnG1() | ||
module, err := f3.New(context.TODO(), 1000 /*TODO expose signing*/, manifest, ds, | ||
params.Host, params.PubSub, &signer{params.Wallet}, verif, ec, log) | ||
|
||
if err != nil { | ||
return nil, xerrors.Errorf("creating F3: %w", err) | ||
} | ||
|
||
var liftimeContext context.Context | ||
var cancel func() | ||
lc.Append(fx.StartStopHook( | ||
func(ctx context.Context) { | ||
liftimeContext, cancel = context.WithCancel(ctx) | ||
go func() { | ||
err := module.Run(0, liftimeContext) | ||
if err != nil { | ||
log.Errorf("running f3: %+v", err) | ||
} | ||
}() | ||
}, func() { | ||
cancel() | ||
})) | ||
|
||
return &F3{ | ||
f3: module, | ||
}, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package lf3 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-f3/gpbft" | ||
"github.com/filecoin-project/lotus/api" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
type signer struct { | ||
wallet api.Wallet | ||
} | ||
|
||
// Signs a message with the secret key corresponding to a public key. | ||
func (s *signer) Sign(sender gpbft.PubKey, msg []byte) ([]byte, error) { | ||
addr, err := address.NewBLSAddress(sender) | ||
if err != nil { | ||
return nil, xerrors.Errorf("converting pubkey to address: %w", err) | ||
} | ||
sig, err := s.wallet.WalletSign(context.TODO(), addr, msg, api.MsgMeta{Type: api.MTUnknown}) | ||
if err != nil { | ||
return nil, xerrors.Errorf("error while signing: %w", err) | ||
} | ||
return sig.Data, nil | ||
} | ||
|
||
// MarshalPayloadForSigning marshals the given payload into the bytes that should be signed. | ||
// This should usually call `Payload.MarshalForSigning(NetworkName)` except when testing as | ||
// that method is slow (computes a merkle tree that's necessary for testing). | ||
// Implementations must be safe for concurrent use. | ||
func (s *signer) MarshalPayloadForSigning(nn gpbft.NetworkName, p *gpbft.Payload) []byte { | ||
return p.MarshalForSigning(nn) | ||
} |