Skip to content

Commit ac376b7

Browse files
committed
ir/container: Reuse already calculated ID in processContainerPut()
Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
1 parent a6954e6 commit ac376b7

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

pkg/innerring/processors/container/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (cp *Processor) handlePut(ev event.Event) {
3535

3636
// send an event to the worker pool
3737

38-
err := cp.pool.Submit(func() { cp.processContainerPut(req) })
38+
err := cp.pool.Submit(func() { cp.processContainerPut(req, id) })
3939
if err != nil {
4040
// there system can be moved into controlled degradation stage
4141
cp.log.Warn("container processor worker pool drained",

pkg/innerring/processors/container/process_container.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ type putContainerContext struct {
2828
e containerEvent.CreateContainerRequest
2929

3030
// must be filled when verifying raw data from e
31-
cID cid.ID
3231
cnr containerSDK.Container
3332
}
3433

3534
// Process a new container from the user by checking the container sanity
3635
// and sending approve tx back to the FS chain.
37-
func (cp *Processor) processContainerPut(req containerEvent.CreateContainerRequest) {
36+
func (cp *Processor) processContainerPut(req containerEvent.CreateContainerRequest, id cid.ID) {
3837
if !cp.alphabetState.IsAlphabet() {
3938
cp.log.Info("non alphabet mode, ignore container put")
4039
return
@@ -53,7 +52,7 @@ func (cp *Processor) processContainerPut(req containerEvent.CreateContainerReque
5352
return
5453
}
5554

56-
cp.approvePutContainer(ctx)
55+
cp.approvePutContainer(ctx, id)
5756
}
5857

5958
const (
@@ -70,7 +69,6 @@ var allowedSystemAttributes = map[string]struct{}{
7069

7170
func (cp *Processor) checkPutContainer(ctx *putContainerContext) error {
7271
binCnr := ctx.e.Container
73-
ctx.cID = cid.NewFromMarshalledContainer(binCnr)
7472

7573
err := ctx.cnr.Unmarshal(binCnr)
7674
if err != nil {
@@ -129,8 +127,8 @@ func (cp *Processor) checkPutContainer(ctx *putContainerContext) error {
129127
return nil
130128
}
131129

132-
func (cp *Processor) approvePutContainer(ctx *putContainerContext) {
133-
l := cp.log.With(zap.Stringer("cID", ctx.cID))
130+
func (cp *Processor) approvePutContainer(ctx *putContainerContext, id cid.ID) {
131+
l := cp.log.With(zap.Stringer("cID", id))
134132
l.Debug("approving new container...")
135133

136134
e := ctx.e
@@ -153,7 +151,7 @@ func (cp *Processor) approvePutContainer(ctx *putContainerContext) {
153151
}
154152

155153
policy := ctx.cnr.PlacementPolicy()
156-
vectors, err := nm.ContainerNodes(policy, ctx.cID)
154+
vectors, err := nm.ContainerNodes(policy, id)
157155
if err != nil {
158156
l.Error("could not build placement for Container contract update", zap.Error(err))
159157
return
@@ -168,7 +166,7 @@ func (cp *Processor) approvePutContainer(ctx *putContainerContext) {
168166
replicas[i] = 1 // each EC part is stored in a single copy
169167
}
170168

171-
err = cp.cnrClient.UpdateContainerPlacement(ctx.cID, vectors, replicas)
169+
err = cp.cnrClient.UpdateContainerPlacement(id, vectors, replicas)
172170
if err != nil {
173171
l.Error("could not update Container contract", zap.Error(err))
174172
return

0 commit comments

Comments
 (0)