Skip to content

Commit af8d85e

Browse files
authored
close file and gzip writer when app finished (#16)
* close file and gzip writer when app finished * update celestia event key * update celestia event value * bug fix query raw_commit
1 parent 5e6554f commit af8d85e

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func (c *baseRPCClient) RawCommit(ctx context.Context, height *int64) ([]byte, e
509509
if height != nil {
510510
params["height"] = height
511511
}
512-
_, err := c.caller.Call(ctx, "commit", params, result)
512+
_, err := c.caller.Call(ctx, "raw_commit", params, result)
513513
if err != nil {
514514
return nil, err
515515
}

executor/batch/batch.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ func (bs *BatchSubmitter) Initialize(ctx context.Context, startHeight uint64, ho
119119
bs.DequeueBatchInfo()
120120
}
121121

122-
fileFlag := os.O_CREATE | os.O_RDWR
122+
fileFlag := os.O_CREATE | os.O_RDWR | os.O_APPEND
123+
bs.batchFile, err = os.OpenFile(bs.homePath+"/batch", fileFlag, 0666)
124+
if err != nil {
125+
return err
126+
}
127+
123128
if bs.node.HeightInitialized() {
124129
bs.localBatchInfo.Start = bs.node.GetHeight()
125130
bs.localBatchInfo.End = 0
@@ -129,14 +134,15 @@ func (bs *BatchSubmitter) Initialize(ctx context.Context, startHeight uint64, ho
129134
if err != nil {
130135
return err
131136
}
132-
} else {
133-
// if the node has already processed blocks, append to the file
134-
fileFlag |= os.O_APPEND
135-
}
136-
137-
bs.batchFile, err = os.OpenFile(bs.homePath+"/batch", fileFlag, 0666)
138-
if err != nil {
139-
return err
137+
// reset batch file
138+
err := bs.batchFile.Truncate(0)
139+
if err != nil {
140+
return err
141+
}
142+
_, err = bs.batchFile.Seek(0, 0)
143+
if err != nil {
144+
return err
145+
}
140146
}
141147
// linux command gzip use level 6 as default
142148
bs.batchWriter, err = gzip.NewWriterLevel(bs.batchFile, 6)
@@ -162,6 +168,15 @@ func (bs *BatchSubmitter) Start(ctx context.Context) {
162168
bs.node.Start(ctx)
163169
}
164170

171+
func (bs *BatchSubmitter) Close() {
172+
if bs.batchWriter != nil {
173+
bs.batchWriter.Close()
174+
}
175+
if bs.batchFile != nil {
176+
bs.batchFile.Close()
177+
}
178+
}
179+
165180
func (bs *BatchSubmitter) SetBridgeInfo(bridgeInfo opchildtypes.BridgeInfo) {
166181
bs.bridgeInfo = bridgeInfo
167182
}

executor/celestia/handler.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package celestia
22

33
import (
44
"context"
5+
"encoding/base64"
56

67
nodetypes "github.com/initia-labs/opinit-bots/node/types"
78
"go.uber.org/zap"
@@ -14,13 +15,24 @@ func (c *Celestia) payForBlobsHandler(_ context.Context, args nodetypes.EventHan
1415

1516
for _, attr := range args.EventAttributes {
1617
switch attr.Key {
17-
// signer
18-
case "signer":
19-
signer = attr.Value
20-
case "blob_sizes":
21-
blobSizes = attr.Value
22-
case "namespaces":
23-
namespaces = attr.Value
18+
case "c2lnbmVy": // signer
19+
value, err := base64.StdEncoding.DecodeString(attr.Value)
20+
if err != nil {
21+
return err
22+
}
23+
signer = string(value)
24+
case "YmxvYl9zaXplcw==": // blob_sizes
25+
value, err := base64.StdEncoding.DecodeString(attr.Value)
26+
if err != nil {
27+
return err
28+
}
29+
blobSizes = string(value)
30+
case "bmFtZXNwYWNlcw==": // namespaces
31+
value, err := base64.StdEncoding.DecodeString(attr.Value)
32+
if err != nil {
33+
return err
34+
}
35+
namespaces = string(value)
2436
}
2537
}
2638
c.logger.Info("record batch",

executor/executor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func (ex *Executor) Start(ctx context.Context) error {
143143
}
144144

145145
func (ex *Executor) Close() {
146+
ex.batch.Close()
146147
ex.db.Close()
147148
}
148149

0 commit comments

Comments
 (0)