Check a ledger operation against the types its binding carries, refusing a ledger bound with none (issue 1966 T2)
This commit is contained in:
@@ -20,21 +20,9 @@ import (
|
||||
// for the module whose bundle or whose repair tool asks, from its own bindings alone, with its types and the connection
|
||||
// its history is published on.
|
||||
|
||||
// LedgerTypes is where the runner reads a ledger's types, by module and local name. Where it reads them from on the
|
||||
// live mesh is not decided (issue 1966: the binding carries no types, and no record names a source); until it is,
|
||||
// the runner refuses to open a ledger and says why, and a test gives the types.
|
||||
type LedgerTypes func(module, local string) ([]catalogue.LedgerType, error)
|
||||
|
||||
// errTypesUndecided is the refusal of a ledger whose types the runner has no source for.
|
||||
func errTypesUndecided(module, local string) error {
|
||||
return fmt.Errorf("the tool runner cannot open %s's ledger %q: it reads a ledger's types from nowhere yet, since its "+
|
||||
"binding carries none and no record names their source (issue 1966)", module, local)
|
||||
}
|
||||
|
||||
// ledgerSource is how the runner opens a module's ledger: its types, and the connection its history and snapshots are
|
||||
// published on (the module's ledger credential, ADR 0597 §9).
|
||||
// ledgerSource is how the runner opens a module's ledger beside its binding: the connection its history and snapshots
|
||||
// are published on (the module's ledger credential, ADR 0597 §9).
|
||||
type ledgerSource struct {
|
||||
types LedgerTypes
|
||||
writer func(module string) (*bus.Conn, error)
|
||||
}
|
||||
|
||||
@@ -97,13 +85,12 @@ func (c *consumers) ledger(module, local string) (*ledger.Ledger, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
types := c.ledgers.types
|
||||
if types == nil {
|
||||
return nil, errTypesUndecided(module, local)
|
||||
}
|
||||
ts, err := types(module, local)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// Its types travel on its binding, copied by the grants part from the entry the manifest-accepted event carries
|
||||
// (mesh-sdk membership.BusBinding.Types): the runner reads no other part's state for them (ADR 0596).
|
||||
ts := b.Types
|
||||
if len(ts) == 0 {
|
||||
return nil, fmt.Errorf("%s's ledger %q is bound with no types, so no operation can be checked against one: its "+
|
||||
"binding carries the types its manifest asks for in `requires` (novox/hq ADR 0597 §1)", module, local)
|
||||
}
|
||||
var writer *bus.Conn
|
||||
if c.ledgers.writer != nil {
|
||||
|
||||
Reference in New Issue
Block a user