sidecar

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2025 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MalformedTxTestCases = []struct {
	Tx             *protoblocktx.Tx
	ExpectedStatus protoblocktx.Status
}{
	{
		Tx: &protoblocktx.Tx{
			Id: "valid TX",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:      "1",
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{Key: []byte("k1")},
					},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_NOT_VALIDATED,
	},
	{
		Tx:             &protoblocktx.Tx{},
		ExpectedStatus: protoblocktx.Status_MALFORMED_MISSING_TX_ID,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "empty namespaces",
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_EMPTY_NAMESPACES,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "missing signature",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:       "1",
					NsVersion:  0,
					ReadWrites: []*protoblocktx.ReadWrite{{Key: []byte("1")}},
				},
			},
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_MISSING_SIGNATURE,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "not enough signatures",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:       "1",
					NsVersion:  0,
					ReadWrites: []*protoblocktx.ReadWrite{{Key: []byte("1")}},
				},
			},
			Signatures: make([][]byte, 0),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_MISSING_SIGNATURE,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "too much signatures",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:       "1",
					NsVersion:  0,
					ReadWrites: []*protoblocktx.ReadWrite{{Key: []byte("1")}},
				},
			},
			Signatures: make([][]byte, 2),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_MISSING_SIGNATURE,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "namespace id is invalid in tx",
			Namespaces: []*protoblocktx.TxNamespace{
				{NsId: "//"},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_NAMESPACE_ID_INVALID,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "no writes",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:      "1",
					NsVersion: 0,
					ReadsOnly: []*protoblocktx.Read{
						{Key: []byte("k1")},
					},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_NO_WRITES,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "namespace id is invalid in metaNs tx",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:      "1",
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{Key: []byte("key")},
					},
				},
				{
					NsId:      types.MetaNamespaceID,
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{Key: []byte("/\\")},
					},
				},
			},
			Signatures: make([][]byte, 2),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_NAMESPACE_ID_INVALID,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "namespace policy is invalid in metaNs tx",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:      "1",
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{Key: []byte("key")},
					},
				},
				{
					NsId:      types.MetaNamespaceID,
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{
							Key:   []byte("2"),
							Value: []byte("value"),
						},
					},
				},
			},
			Signatures: make([][]byte, 2),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_NAMESPACE_POLICY_INVALID,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "duplicate namespace",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:      "1",
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{Key: []byte("key")},
					},
				},
				{
					NsId:      "1",
					NsVersion: 0,
				},
			},
			Signatures: make([][]byte, 2),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_DUPLICATE_NAMESPACE,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "valid namespace TX",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:      types.MetaNamespaceID,
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{
							Key:   []byte("2"),
							Value: defaultNsValidPolicy(),
						},
					},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_NOT_VALIDATED,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "valid namespace TX with regular TX",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:      "1",
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{Key: []byte("key")},
					},
				},
				{
					NsId:      types.MetaNamespaceID,
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{
							Key:   []byte("2"),
							Value: defaultNsValidPolicy(),
						},
					},
				},
			},
			Signatures: make([][]byte, 2),
		},
		ExpectedStatus: protoblocktx.Status_NOT_VALIDATED,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "invalid policy",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:      types.MetaNamespaceID,
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{
							Key:   []byte("2"),
							Value: defaultNsInvalidPolicy(),
						},
					},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_NAMESPACE_POLICY_INVALID,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "blind writes not allowed in metaNs tx",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:      "1",
					NsVersion: 0,
					ReadWrites: []*protoblocktx.ReadWrite{
						{
							Key: []byte("key"),
						},
					},
				},
				{
					NsId:      types.MetaNamespaceID,
					NsVersion: 0,
					BlindWrites: []*protoblocktx.Write{
						{
							Key:   []byte("2"),
							Value: defaultNsInvalidPolicy(),
						},
					},
				},
			},
			Signatures: make([][]byte, 2),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_BLIND_WRITES_NOT_ALLOWED,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "nil key in ReadOnly",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:       "1",
					NsVersion:  0,
					ReadsOnly:  []*protoblocktx.Read{{Key: nil}},
					ReadWrites: []*protoblocktx.ReadWrite{{Key: []byte("1")}},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_EMPTY_KEY,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "nil key in ReadWrites",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:       "1",
					NsVersion:  0,
					ReadWrites: []*protoblocktx.ReadWrite{{Key: nil}},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_EMPTY_KEY,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "nil key in BlindWrites",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:        "1",
					NsVersion:   0,
					BlindWrites: []*protoblocktx.Write{{Key: nil}},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_EMPTY_KEY,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "duplicate key within ReadOnly",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:       "1",
					NsVersion:  0,
					ReadsOnly:  []*protoblocktx.Read{{Key: []byte("key1")}, {Key: []byte("key1")}},
					ReadWrites: []*protoblocktx.ReadWrite{{Key: []byte("1")}},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_DUPLICATE_KEY_IN_READ_WRITE_SET,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "duplicate key within ReadWrite",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:       "1",
					NsVersion:  0,
					ReadWrites: []*protoblocktx.ReadWrite{{Key: []byte("key1")}, {Key: []byte("key1")}},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_DUPLICATE_KEY_IN_READ_WRITE_SET,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "duplicate key within BlindWrites",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:        "1",
					NsVersion:   0,
					BlindWrites: []*protoblocktx.Write{{Key: []byte("key1")}, {Key: []byte("key1")}},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_DUPLICATE_KEY_IN_READ_WRITE_SET,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "duplicate key across ReadOnly and ReadWrite",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:       "1",
					NsVersion:  0,
					ReadsOnly:  []*protoblocktx.Read{{Key: []byte("key1")}},
					ReadWrites: []*protoblocktx.ReadWrite{{Key: []byte("key1")}},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_DUPLICATE_KEY_IN_READ_WRITE_SET,
	},
	{
		Tx: &protoblocktx.Tx{
			Id: "duplicate key across ReadWrite and BlindWrites",
			Namespaces: []*protoblocktx.TxNamespace{
				{
					NsId:        "1",
					NsVersion:   0,
					ReadWrites:  []*protoblocktx.ReadWrite{{Key: []byte("key1")}},
					BlindWrites: []*protoblocktx.Write{{Key: []byte("key1")}},
				},
			},
			Signatures: make([][]byte, 1),
		},
		ExpectedStatus: protoblocktx.Status_MALFORMED_DUPLICATE_KEY_IN_READ_WRITE_SET,
	},
}

MalformedTxTestCases are valid and invalid TXs due to malformed.

Functions

func IsStatusStoredInDB added in v0.1.5

func IsStatusStoredInDB(status protoblocktx.Status) bool

IsStatusStoredInDB returns true if the given status code can be stored in the state DB.

func LoadBootstrapConfig

func LoadBootstrapConfig(conf *Config) error

LoadBootstrapConfig loads the bootstrap config according to the bootstrap method.

func OverwriteConfigFromBlock

func OverwriteConfigFromBlock(conf *Config, configBlock *common.Block) error

OverwriteConfigFromBlock overwrites the orderer connection with fields from a config block.

func OverwriteConfigFromBlockFile

func OverwriteConfigFromBlockFile(conf *Config) error

OverwriteConfigFromBlockFile overwrites the orderer connection with fields from the bootstrap config block.

func OverwriteConfigFromEnvelope

func OverwriteConfigFromEnvelope(conf *Config, envelope *common.Envelope) error

OverwriteConfigFromEnvelope overwrites the orderer connection with fields from a config transaction. For now, it fetches the following: - Orderer endpoints. TODO: Fetch Root CAs.

func RequireNotifications added in v0.1.5

func RequireNotifications(
	t *testing.T,
	notifyStream protonotify.Notifier_OpenNotificationStreamClient,
	expectedBlockNumber uint64,
	txIDs []string,
	status []protoblocktx.Status,
)

RequireNotifications verifies that the expected notification were received.

Types

type Bootstrap

type Bootstrap struct {
	// GenesisBlockFilePath is the path for the genesis block.
	// If omitted, the local configuration will be used.
	GenesisBlockFilePath string `mapstructure:"genesis-block-file-path" yaml:"genesis-block-file-path,omitempty"`
}

Bootstrap configures how to obtain the bootstrap configuration.

type Config

type Config struct {
	Server                        *connection.ServerConfig  `mapstructure:"server"`
	Monitoring                    monitoring.Config         `mapstructure:"monitoring"`
	Committer                     CoordinatorConfig         `mapstructure:"committer"`
	Orderer                       broadcastdeliver.Config   `mapstructure:"orderer"`
	Ledger                        LedgerConfig              `mapstructure:"ledger"`
	Notification                  NotificationServiceConfig `mapstructure:"notification"`
	LastCommittedBlockSetInterval time.Duration             `mapstructure:"last-committed-block-set-interval"`
	WaitingTxsLimit               int                       `mapstructure:"waiting-txs-limit"`
	// ChannelBufferSize is the buffer size that will be used to queue blocks, requests, and statuses.
	ChannelBufferSize int       `mapstructure:"channel-buffer-size"`
	Bootstrap         Bootstrap `mapstructure:"bootstrap"`
}

Config holds the configuration of the sidecar service. This includes sidecar endpoint, committer endpoint to which the sidecar pushes the block and pulls statuses, and the config of ledger service, and the orderer setup. It may contain the orderer endpoint from which the sidecar pulls blocks.

type CoordinatorConfig

type CoordinatorConfig struct {
	Endpoint connection.Endpoint `mapstructure:"endpoint"`
}

CoordinatorConfig holds the endpoint of the coordinator component in the committer service.

type LedgerConfig

type LedgerConfig struct {
	Path string `mapstructure:"path"`
}

LedgerConfig holds the ledger path.

type NotificationServiceConfig added in v0.1.5

type NotificationServiceConfig struct {
	// MaxTimeout is an upper limit on the request's timeout to prevent resource exhaustion.
	// If a request doesn't specify a timeout, this value will be used.
	MaxTimeout time.Duration `mapstructure:"max-timeout"`
}

NotificationServiceConfig holds the parameters for notifications.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a relay service which relays the block from orderer to committer. Further, it aggregates the transaction status and forwards the validated block to clients who have registered on the ledger server.

func New

func New(c *Config) (*Service, error)

New creates a sidecar service.

func (*Service) Close

func (s *Service) Close()

Close closes the ledger.

func (*Service) RegisterService added in v0.1.5

func (s *Service) RegisterService(server *grpc.Server)

RegisterService registers for the sidecar's GRPC services.

func (*Service) Run

func (s *Service) Run(ctx context.Context) error

Run starts the sidecar service. The call to Run blocks until an error occurs or the context is canceled.

func (*Service) WaitForReady

func (*Service) WaitForReady(context.Context) bool

WaitForReady wait for sidecar to be ready to be exposed as gRPC service. If the context ended before the service is ready, returns false.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL