@@ -3,6 +3,7 @@ package allocation
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
+ "github.com/0chain/blobber/code/go/0chain.net/core/node"
6
7
"time"
7
8
8
9
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
@@ -101,7 +102,7 @@ func updateWork(ctx context.Context) {
101
102
offset += int64 (len (allocs ))
102
103
103
104
for _ , a := range allocs {
104
- updateAllocation (ctx , a )
105
+ updateAllocation (ctx , a , node . Self . ID )
105
106
if waitOrQuit (ctx , REQUEST_TIMEOUT ) {
106
107
return
107
108
}
@@ -120,7 +121,7 @@ func shouldFinalize(sa *transaction.StorageAllocation) bool {
120
121
return sa .Expiration < now && ! sa .Finalized
121
122
}
122
123
123
- func updateAllocation (ctx context.Context , a * Allocation ) {
124
+ func updateAllocation (ctx context.Context , a * Allocation , selfBlobberID string ) {
124
125
if a .Finalized {
125
126
cleanupAllocation (ctx , a )
126
127
return
@@ -132,6 +133,19 @@ func updateAllocation(ctx context.Context, a *Allocation) {
132
133
return
133
134
}
134
135
136
+ removedBlobber := true
137
+ for _ , d := range sa .BlobberDetails {
138
+ if d .BlobberID == selfBlobberID {
139
+ removedBlobber = false
140
+ break
141
+ }
142
+ }
143
+
144
+ if removedBlobber {
145
+ logging .Logger .Info ("blobber removed from allocation" , zap .String ("blobber" , selfBlobberID ), zap .String ("allocation" , a .ID ))
146
+ cleanupAllocation (ctx , a )
147
+ }
148
+
135
149
// if new Tx, then we have to update the allocation
136
150
if sa .Tx != a .Tx || sa .OwnerID != a .OwnerID || sa .Finalized != a .Finalized {
137
151
if a , err = updateAllocationInDB (ctx , a , sa ); err != nil {
@@ -142,7 +156,7 @@ func updateAllocation(ctx context.Context, a *Allocation) {
142
156
143
157
// send finalize allocation transaction
144
158
if shouldFinalize (sa ) {
145
- sendFinalizeAllocation (a )
159
+ sendFinalizeAllocation (a . ID )
146
160
return
147
161
}
148
162
@@ -217,17 +231,16 @@ type finalizeRequest struct {
217
231
AllocationID string `json:"allocation_id"`
218
232
}
219
233
220
- func sendFinalizeAllocation (a * Allocation ) {
234
+ func sendFinalizeAllocation (allocationID string ) {
221
235
var tx , err = transaction .NewTransactionEntity ()
222
236
if err != nil {
223
237
logging .Logger .Error ("creating new transaction entity" , zap .Error (err ))
224
238
return
225
239
}
226
240
227
241
var request finalizeRequest
228
- request .AllocationID = a . ID
242
+ request .AllocationID = allocationID
229
243
230
- // TODO should this be verified?
231
244
err = tx .ExecuteSmartContract (
232
245
transaction .STORAGE_CONTRACT_ADDRESS ,
233
246
transaction .FINALIZE_ALLOCATION ,
0 commit comments