Skip to content

Commit 0130dc1

Browse files
committed
temporary fix for pool join
due to chain sync some members cannot join pool. calling api.fula directly
1 parent 6b15da4 commit 0130dc1

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

blockchain/bl_pool.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ func (bl *FxBlockchain) HandlePoolJoin(method string, action string, from peer.I
7474
}
7575

7676
//TODO: Ensure it is optimized for long-running calls
77+
//TODO: replace callBlockchainWithSeedTemporary with callBlockchain after fixing sync chain issue
7778
ctx, cancel := context.WithTimeout(r.Context(), time.Second*time.Duration(bl.timeout))
7879
defer cancel()
79-
response, statusCode, err := bl.callBlockchain(ctx, method, action, &req)
80+
response, statusCode, err := bl.callBlockchainWithSeedTemporary(ctx, method, action, &req)
8081
if err != nil {
8182
poolID := req.PoolID
8283
poolIDStr := strconv.Itoa(poolID)

blockchain/blockchain.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,51 @@ func (bl *FxBlockchain) callBlockchain(ctx context.Context, method string, actio
288288
return b, resp.StatusCode, nil
289289
}
290290

291+
// TODO: The below method should be removed after fixing hte syncing issue with blockchain
292+
func (bl *FxBlockchain) callBlockchainWithSeedTemporary(ctx context.Context, method string, action string, p interface{}) ([]byte, int, error) {
293+
// Check blockchain health before proceeding
294+
if err := bl.checkHealth(ctx); err != nil {
295+
return nil, http.StatusFailedDependency, err // Use 424 as the status code for a syncing blockchain
296+
}
297+
298+
endpoint := prependProtocol("api.node3.functionyard.fula.network")
299+
addr := endpoint + "/" + strings.Replace(action, "-", "/", -1)
300+
301+
// Use the bufPool and reqPool to reuse bytes.Buffer and http.Request objects
302+
buf := bl.bufPool.Get().(*bytes.Buffer)
303+
req := bl.reqPool.Get().(*http.Request)
304+
defer func() {
305+
bl.putBuf(buf)
306+
bl.putReq(req)
307+
}()
308+
309+
preparedRequest := bl.PlugSeedIfNeeded(ctx, action, p)
310+
if err := json.NewEncoder(buf).Encode(preparedRequest); err != nil {
311+
return nil, 0, err
312+
}
313+
req, err := http.NewRequestWithContext(ctx, method, addr, buf)
314+
if err != nil {
315+
return nil, 0, err
316+
}
317+
318+
req.Header.Set("Content-Type", "application/json")
319+
320+
resp, err := bl.ch.Do(req)
321+
if err != nil {
322+
return nil, 0, err
323+
}
324+
defer resp.Body.Close()
325+
326+
var bufRes bytes.Buffer
327+
_, err = io.Copy(&bufRes, resp.Body)
328+
if err != nil {
329+
return nil, resp.StatusCode, err
330+
}
331+
b := bufRes.Bytes()
332+
333+
return b, resp.StatusCode, nil
334+
}
335+
291336
func (bl *FxBlockchain) PlugSeedIfNeeded(ctx context.Context, action string, req interface{}) interface{} {
292337
switch action {
293338
case actionSeeded, actionAccountExists, actionAccountFund, actionPoolCreate, actionPoolJoin, actionPoolCancelJoin, actionPoolVote, actionPoolLeave, actionManifestUpload, actionManifestStore, actionManifestRemove, actionManifestRemoveStorer, actionManifestRemoveStored, actionManifestBatchUpload, actionManifestBatchStore:

0 commit comments

Comments
 (0)