diff --git a/block/manager.go b/block/manager.go index df4195a57b..52d7ab8f56 100644 --- a/block/manager.go +++ b/block/manager.go @@ -849,19 +849,13 @@ func (m *Manager) execCreateBlock(_ context.Context, height uint64, lastSignatur return header, blockData, nil } -type headerContextKey struct{} - -// HeaderContextKey is used to store the header in the context. -// This is useful if the execution client needs to access the header during transaction execution. -var HeaderContextKey = headerContextKey{} - func (m *Manager) execApplyBlock(ctx context.Context, lastState types.State, header *types.SignedHeader, data *types.Data) (types.State, error) { rawTxs := make([][]byte, len(data.Txs)) for i := range data.Txs { rawTxs[i] = data.Txs[i] } - ctx = context.WithValue(ctx, HeaderContextKey, header) + ctx = context.WithValue(ctx, types.SignedHeaderContextKey, header) newStateRoot, _, err := m.exec.ExecuteTxs(ctx, rawTxs, header.Height(), header.Time(), lastState.AppHash) if err != nil { return types.State{}, fmt.Errorf("failed to execute transactions: %w", err) diff --git a/types/signed_header.go b/types/signed_header.go index b798941986..6121f9d01c 100644 --- a/types/signed_header.go +++ b/types/signed_header.go @@ -2,12 +2,28 @@ package types import ( "bytes" + "context" "errors" "fmt" "github.com/celestiaorg/go-header" ) +type signedHeaderContextKey struct{} + +// SignedHeaderContextKey is used to store the signed header in the context. +// This is useful if the execution client needs to access the signed header during transaction execution. +var SignedHeaderContextKey = signedHeaderContextKey{} + +func SignedHeaderFromContext(ctx context.Context) (*SignedHeader, bool) { + sh, ok := ctx.Value(SignedHeaderContextKey).(*SignedHeader) + if !ok { + return nil, false + } + + return sh, true +} + var ( // ErrLastHeaderHashMismatch is returned when the last header hash doesn't match. ErrLastHeaderHashMismatch = errors.New("last header hash mismatch")