Skip to content

Commit 22b8e62

Browse files
request verification in batcher (#279)
Signed-off-by: Dor.Katzelnick <[email protected]>
1 parent 7cb6323 commit 22b8e62

21 files changed

+145
-165
lines changed

node/batcher/batcher.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,24 @@ func (b *Batcher) Deliver(stream orderer.AtomicBroadcast_DeliverServer) error {
144144
}
145145

146146
func (b *Batcher) Submit(ctx context.Context, req *protos.Request) (*protos.SubmitResponse, error) {
147+
// TODO: certificate pinning (bathcer trust router from his own party.)
148+
b.logger.Debugf("Received request %x", req.Payload)
149+
150+
if err := b.requestsInspectorVerifier.VerifyRequestFromRouter(req); err != nil {
151+
b.logger.Panicf("Failed verifying request before submitting from router; err: %v", err)
152+
// TODO should return response with error?
153+
}
154+
147155
traceId := req.TraceId
148156
req.TraceId = nil
149-
150157
rawReq, err := proto.Marshal(req)
151158
if err != nil {
152159
b.logger.Panicf("Failed marshaling request: %v", err)
153160
}
154161

155-
b.logger.Infof("Received request %x", req.Payload)
156-
157162
var resp protos.SubmitResponse
158163
resp.TraceId = traceId
159-
if err := b.requestsInspectorVerifier.VerifyRequest(rawReq); err != nil {
160-
// TODO make sure the router verifies the request
161-
b.logger.Panicf("Failed verifying request before submitting from router; err: %v", err)
162-
}
164+
163165
if err := b.batcher.Submit(rawReq); err != nil {
164166
resp.Error = err.Error()
165167
}
@@ -168,6 +170,7 @@ func (b *Batcher) Submit(ctx context.Context, req *protos.Request) (*protos.Subm
168170
}
169171

170172
func (b *Batcher) SubmitStream(stream protos.RequestTransmit_SubmitStreamServer) error {
173+
// TODO: certificate pinning (bathcer trust router form his own party.)
171174
stop := make(chan struct{})
172175
defer close(stop)
173176

@@ -193,9 +196,13 @@ func (b *Batcher) dispatchRequests(stream protos.RequestTransmit_SubmitStreamSer
193196
return err
194197
}
195198

199+
if err := b.requestsInspectorVerifier.VerifyRequestFromRouter(req); err != nil {
200+
b.logger.Panicf("Failed verifying request before submitting from router; err: %v", err)
201+
// TODO should return response with error?
202+
}
203+
196204
traceId := req.TraceId
197205
req.TraceId = nil
198-
199206
rawReq, err := proto.Marshal(req)
200207
if err != nil {
201208
b.logger.Panicf("Failed marshaling request: %v", err)
@@ -204,10 +211,6 @@ func (b *Batcher) dispatchRequests(stream protos.RequestTransmit_SubmitStreamSer
204211
var resp protos.SubmitResponse
205212
resp.TraceId = traceId
206213

207-
if err := b.requestsInspectorVerifier.VerifyRequest(rawReq); err != nil {
208-
// TODO make sure the router verifies the request
209-
b.logger.Panicf("Failed verifying request before submitting from router; err: %v", err)
210-
}
211214
if err := b.batcher.Submit(rawReq); err != nil {
212215
resp.Error = err.Error()
213216
}
@@ -267,6 +270,7 @@ func (b *Batcher) FwdRequestStream(stream protos.BatcherControlService_FwdReques
267270
b.logger.Debugf("Calling submit request from batcher %d", from)
268271
if err := b.requestsInspectorVerifier.VerifyRequest(msg.Request); err != nil {
269272
b.logger.Infof("Failed verifying request before submitting from batcher %d; err: %v", from, err)
273+
continue
270274
}
271275
if err := b.batcher.Submit(msg.Request); err != nil {
272276
if strings.Contains(err.Error(), "already inserted") {

node/batcher/batcher_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func CreateBatcher(conf *node_config.BatcherNodeConfig, logger types.Logger, net
5151
}
5252

5353
func NewBatcher(logger types.Logger, config *node_config.BatcherNodeConfig, ledger *node_ledger.BatchLedgerArray, bp BatchesPuller, ds *BatcherDeliverService, sr StateReplicator, senderCreator ConsenterControlEventSenderCreator, net Net, signer Signer) *Batcher {
54-
requestsIDAndVerifier := NewRequestsInspectorVerifier(logger, config, &NoopClientRequestSigVerifier{}, nil)
54+
requestsIDAndVerifier := NewRequestsInspectorVerifier(logger, config, nil)
5555

5656
configStore, err := configstore.NewStore(config.ConfigStorePath)
5757
if err != nil {

node/batcher/mocks/baf_creator.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/batcher/mocks/baf_sender.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/batcher/mocks/batch_acker.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/batcher/mocks/batch_ledger.go

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/batcher/mocks/batched_requests_verifier.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/batcher/mocks/batches_puller.go

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/batcher/mocks/complainer.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/batcher/mocks/consensus_state_replicator_creator.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)