Skip to content

Commit 3153014

Browse files
committed
added wait for the nft verifier to sync, via channels, added a new transaction called polygon_checkpoint to the prepare block and added verification for it in process block
1 parent 738363b commit 3153014

File tree

11 files changed

+390
-148
lines changed

11 files changed

+390
-148
lines changed

config.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
12
p2p:
23
# 0.0.0.0 = localhost
34
addr: 0.0.0.0
45
# 0 = random port
56
port: 0
67
groupName: xnode
78
peerLimit: 50
9+
nft:
10+
rpcAddress: https://rpc.ankr.com/eth_sepolia
11+
unlimitedRPC: false
12+
eventSignature: Redeemed(uint256,bytes32)
13+
searchLimit: 3000
14+
deployBlock: 5618691
15+
confirmations: 20
16+
timing: 90
817
bft:
918
homeDir: cbft-home
1019
db:
@@ -30,7 +39,5 @@ log:
3039
maxSize: 10
3140
maxAge: 7
3241
maxBackups: 10
33-
nft:
34-
trackerData: ./cbft/data/nft-tracked
35-
rpcAddress: https://rpc.ankr.com/eth_sepolia
36-
unlimitedRPC: false
42+
43+

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
module github.com/openmesh-network/core
22

3-
go 1.21
3+
go 1.22.1
4+
5+
toolchain go1.22.2
46

57
require (
8+
github.com/Openmesh-Network/nft-authorise v0.0.0-20240509074056-66765710e7e3
69
github.com/cometbft/cometbft v0.38.6
710
github.com/dgraph-io/badger/v3 v3.2103.5
811
github.com/ethereum/go-ethereum v1.13.14

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV
2020
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
2121
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
2222
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
23+
github.com/Openmesh-Network/nft-authorise v0.0.0-20240509074056-66765710e7e3 h1:taqsq0MvVecbZAGNDLhfdj9pHNVaET7VRbUu3I6EG8Y=
24+
github.com/Openmesh-Network/nft-authorise v0.0.0-20240509074056-66765710e7e3/go.mod h1:UTMg2S2HcIGf8+XOIow8bXyYOcPZS2CgKRIHdZthaJg=
2325
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
2426
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
2527
github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40=

internal/bft/abci/abci.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package verificationApp
33
import (
44
"context"
55
"encoding/base64"
6+
"fmt"
67
"sort"
78

9+
validatorpass_tracker "github.com/Openmesh-Network/nft-authorise/tracker"
810
abcitypes "github.com/cometbft/cometbft/abci/types"
911
nm "github.com/cometbft/cometbft/node"
1012
comettype "github.com/cometbft/cometbft/types"
@@ -31,6 +33,8 @@ type VerificationApp struct {
3133
Node *nm.Node
3234
CurrentMempool []comettype.Tx
3335
Currblockno int64
36+
PolygonCheckpoint uint64
37+
Tracker *validatorpass_tracker.Tracker
3438
}
3539

3640
const VALIDATOR_PREALLOCATED_COUNT = 2000
@@ -96,8 +100,26 @@ func (app *VerificationApp) PrepareProposal(_ context.Context, proposal *abcityp
96100
}
97101
log.Debug("Marshaling Done")
98102
transactions := comettype.Tx(transactionBytes[:])
99-
proposal.Txs = append(othertx, transactions)
100103

104+
transactionMessage_checkpoint := types.Transaction{
105+
Owner: "trial",
106+
Signature: "",
107+
Type: *types.TransactionType_PolygonCheckpointTransaction.Enum(),
108+
}
109+
transactionMessage_checkpoint.Data = &types.Transaction_PolygonCheckpointTransactionData{
110+
PolygonCheckpointTransactionData: &types.PolygonCheckpointTransactionData{
111+
Blockno: uint64(app.Tracker.LastTrackerHeight),
112+
Blockhash: "xyz", //not a necessary field just nice to have for record keeping
113+
},
114+
}
115+
transactionBytes_Checkpoint, err := proto.Marshal(&transactionMessage_checkpoint)
116+
if err != nil {
117+
panic(err)
118+
}
119+
120+
transactions_checkpoint := comettype.Tx(transactionBytes_Checkpoint[:])
121+
proposal.Txs = append(othertx, transactions, transactions_checkpoint)
122+
log.Debug(proposal.Txs)
101123
return &abcitypes.ResponsePrepareProposal{Txs: proposal.Txs}, nil
102124
}
103125
func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcitypes.RequestProcessProposal) (*abcitypes.ResponseProcessProposal, error) {
@@ -143,6 +165,7 @@ func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcityp
143165

144166
if code := app.isValid(tx); code != 0 {
145167
// log.Error("Error: invalid transaction index %v", i)
168+
log.Error("A transaction got error")
146169
return &abcitypes.ResponseProcessProposal{Status: abcitypes.ResponseProcessProposal_REJECT}, nil
147170
} else {
148171
var transaction types.Transaction
@@ -151,8 +174,9 @@ func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcityp
151174
log.Error("Error unmarshaling transaction data:", err)
152175
return &abcitypes.ResponseProcessProposal{Status: abcitypes.ResponseProcessProposal_REJECT}, nil
153176
}
154-
177+
log.Debug(transaction.Type)
155178
switch transaction.Type {
179+
156180
case types.TransactionType_SummaryTransaction:
157181

158182
summaryData := &types.SummaryTransactionData{}
@@ -168,6 +192,20 @@ func (app *VerificationApp) ProcessProposal(_ context.Context, proposal *abcityp
168192
}
169193
log.Debug("they are similar")
170194

195+
case types.TransactionType_PolygonCheckpointTransaction:
196+
log.Debug("polygon tx found")
197+
checkpointData := &types.PolygonCheckpointTransactionData{}
198+
checkpointData = transaction.GetPolygonCheckpointTransactionData()
199+
200+
if err != nil {
201+
log.Error("Cannot decode tx")
202+
return &abcitypes.ResponseProcessProposal{Status: abcitypes.ResponseProcessProposal_REJECT}, nil
203+
}
204+
205+
if checkpointData.Blockno > uint64(app.Tracker.LastTrackerHeight) {
206+
return &abcitypes.ResponseProcessProposal{Status: abcitypes.ResponseProcessProposal_REJECT}, nil
207+
}
208+
log.Debug("the height is okay,the proposed height is ", checkpointData.Blockno, "the current height is", app.Tracker.LastTrackerHeight)
171209
default:
172210
log.Debug(transaction.Type)
173211
log.Debug("Unknown transaction type")
@@ -286,6 +324,12 @@ func (app *VerificationApp) FinalizeBlock(_ context.Context, req *abcitypes.Requ
286324
log.Debug("Node succesfully registered: ", len(validatorupdates))
287325
// log.Debug("Node Registration Transaction Data:", registrationData)
288326

327+
case types.TransactionType_PolygonCheckpointTransaction:
328+
polygonData := &types.PolygonCheckpointTransactionData{}
329+
polygonData = transaction.GetPolygonCheckpointTransactionData()
330+
app.PolygonCheckpoint = polygonData.Blockno
331+
fmt.Println("The polygon checkpoint is ", app.PolygonCheckpoint)
332+
txs[i] = &abcitypes.ExecTxResult{}
289333
case types.TransactionType_SummaryTransaction:
290334
txs[i] = &abcitypes.ExecTxResult{}
291335
default:
@@ -485,6 +529,17 @@ func (app *VerificationApp) isValid(tx []byte) uint32 {
485529
// log.Debug("Resource Transaction Data:", nodeRegistrationData)
486530
return 0
487531

532+
case types.TransactionType_PolygonCheckpointTransaction:
533+
polygonData := &types.PolygonCheckpointTransactionData{}
534+
polygonData = transaction.GetPolygonCheckpointTransactionData()
535+
536+
if polygonData == nil {
537+
log.Error("Error unmarshaling resource transaction data:", err)
538+
return 1
539+
}
540+
// log.Debug("Resource Transaction Data:", nodeRegistrationData)
541+
return 0
542+
488543
default:
489544
log.Error("Unknown transaction type")
490545
return 1

internal/bft/cometbft.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"time"
1010

11+
validatorpass_tracker "github.com/Openmesh-Network/nft-authorise/tracker"
1112
cfg "github.com/cometbft/cometbft/config"
1213
cmtflags "github.com/cometbft/cometbft/libs/cli/flags"
1314
cmtlog "github.com/cometbft/cometbft/libs/log"
@@ -269,6 +270,11 @@ func (inst *Instance) Start(ctx context.Context) {
269270
}()
270271
}
271272

273+
func (i *Instance) SetTracker(tracker *validatorpass_tracker.Tracker) error {
274+
i.app.Tracker = tracker
275+
return nil
276+
}
277+
272278
// Stop the CometBFT node
273279
func (i *Instance) Stop() error {
274280
err := i.BftNode.Stop()

0 commit comments

Comments
 (0)