Skip to content

Commit 28a262b

Browse files
committed
TLE Evaluation changes, including mute comment etc
1 parent be9a985 commit 28a262b

File tree

10 files changed

+26
-21
lines changed

10 files changed

+26
-21
lines changed

ecc_go/chaincode/enclave_go/tle_stub.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"bytes"
1111
"context"
1212
"crypto/sha256"
13-
"log"
1413

1514
"google.golang.org/grpc"
1615

@@ -87,7 +86,7 @@ func (s *TleStubInterface) GetMeta(key string) ([]byte, error) {
8786
}
8887
response, err := client.GetMeta(context.Background(), request)
8988
if err != nil {
90-
log.Fatalf("Failed to call GetMeta: %v", err)
89+
logger.Errorf("Failed to call GetMeta: %v", err)
9190
return nil, err
9291
}
9392

tle_go/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ COPY client ${CC_PATH}/client
4444
WORKDIR ${CC_PATH}
4545
EXPOSE ${CAAS_PORT}
4646
EXPOSE 50051
47+
EXPOSE 6060
4748

4849
CMD ["tle"]
4950
# CMD ["sleep", "infinity"]

tle_go/enclave.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"exe": "tle",
33
"key": "private.pem",
44
"debug": true,
5-
"heapSize": 512,
5+
"heapSize": 1024,
66
"productID": 1,
77
"securityVersion": 1,
88
"mounts": [

tle_go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
)
1515

1616
// replace github.com/hyperledger/fabric => ../../fabric
17-
replace github.com/hyperledger/fabric => github.com/Flamewind97/fabric v0.0.0-20230727155655-d2a858c57147
17+
replace github.com/hyperledger/fabric => github.com/Flamewind97/fabric v0.0.0-20230809115753-2bd56f3b43c3
1818

1919
require (
2020
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect

tle_go/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
66
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
77
github.com/DataDog/zstd v1.4.0 h1:vhoV+DUHnRZdKW1i5UMjAk2G4JY8wN4ayRfYDNdEhwo=
88
github.com/DataDog/zstd v1.4.0/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
9-
github.com/Flamewind97/fabric v0.0.0-20230727155655-d2a858c57147 h1:tAlIoR8J3cboeUzHH7zCS2yTB78WKk+CYz/C8GT3xac=
10-
github.com/Flamewind97/fabric v0.0.0-20230727155655-d2a858c57147/go.mod h1:RTJcHdhOrpiAqZLNkpVSoz/yaxW/Wiy7sCw/zYO4LjY=
9+
github.com/Flamewind97/fabric v0.0.0-20230809115753-2bd56f3b43c3 h1:gPfELpLOzEzc5etlPSRgqpPNOmfK8SCsz8Sn9ml8bew=
10+
github.com/Flamewind97/fabric v0.0.0-20230809115753-2bd56f3b43c3/go.mod h1:RTJcHdhOrpiAqZLNkpVSoz/yaxW/Wiy7sCw/zYO4LjY=
1111
github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg=
1212
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
1313
github.com/Microsoft/go-winio v0.4.12 h1:xAfWHN1IrQ0NJ9TBC0KBZoqLjzDTr1ML+4MywiUOryc=

tle_go/listener/listener.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,15 @@ func (r *deliverClient) readUntilClose(blockChan chan cb.Block) {
7272
fmt.Println("Got status ", t)
7373
return
7474
case *ab.DeliverResponse_Block:
75-
fmt.Println("Received block: ", t.Block.Header.Number)
76-
blockChan <- *t.Block
77-
7875
if !r.quiet {
76+
fmt.Println("Received block: ", t.Block.Header.Number)
7977
fmt.Scanln() // wait for Enter Key
8078
err := protolator.DeepMarshalJSON(os.Stdout, t.Block)
8179
if err != nil {
8280
fmt.Printf(" Error pretty printing block: %s", err)
8381
}
8482
}
83+
blockChan <- *t.Block
8584
}
8685
}
8786
}

tle_go/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
54
"os"
65
"path/filepath"
76

@@ -37,8 +36,6 @@ func main() {
3736
}
3837
blockListener := listener.NewOrdererBlockGetter(channelID, serverAddr, caCertPath)
3938
// blockListener := listener.NewFileBlockGetter()
40-
fmt.Scanln()
41-
4239
// fmt.Println("--- in TLE_go main.go start to create grpc server.---")
4340

4441
readConfig()

tle_go/tlecore/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type TleServer struct {
1818
func (s *TleServer) GetMeta(ctx context.Context, req *pb.MetaRequest) (*pb.MetaResponse, error) {
1919
namespace := req.Namespace
2020
key := req.Key
21-
fmt.Printf("--- tle_go/server.go getMeta, namespace = %s, key = %s ---\n", namespace, key)
21+
// fmt.Printf("--- tle_go/server.go getMeta, namespace = %s, key = %s ---\n", namespace, key)
2222

2323
data, err := s.tleState.GetMeta(namespace, key)
2424
if err != nil {
@@ -30,7 +30,7 @@ func (s *TleServer) GetMeta(ctx context.Context, req *pb.MetaRequest) (*pb.MetaR
3030
}
3131

3232
func (s *TleServer) GetSession(ctx context.Context, req *pb.Empty) (*pb.MetaResponse, error) {
33-
fmt.Printf("--- tle_go/server.go getSession ---\n")
33+
// fmt.Printf("--- tle_go/server.go getSession ---\n")
3434
data := []byte("")
3535
lastCommitHash := []byte("Sample Commit Hash")
3636
return &pb.MetaResponse{Data: data, LastCommitHash: lastCommitHash}, nil

tle_go/tlecore/tle_peer.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/sha256"
55
"encoding/base64"
66
"fmt"
7+
"time"
78

89
"github.com/hyperledger/fabric-protos-go/common"
910
"github.com/hyperledger/fabric/common/policies"
@@ -72,9 +73,9 @@ func (p *TlePeer) UpdateState(block *common.Block) error {
7273
for tIdx := range block.Data.Data {
7374
// TODO: continue if current txn is invalid.
7475
txsfltr := ValidationFlags(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
75-
fmt.Printf("blockNum %d, tIdx: %d, validationCode: %v\n", tIdx, block.Header.Number, txsfltr.Flag(tIdx))
76+
// fmt.Printf("blockNum %d, tIdx: %d, validationCode: %v\n", block.Header.Number, tIdx, txsfltr.Flag(tIdx))
7677
if txsfltr.IsInvalid(tIdx) {
77-
fmt.Println("The current txn is not valid!")
78+
fmt.Printf("blockNum %d, tIdx: %d, validationCode: %v, current txn is not valid!\n", block.Header.Number, tIdx, txsfltr.Flag(tIdx))
7879
continue
7980
}
8081

@@ -91,15 +92,15 @@ func (p *TlePeer) UpdateState(block *common.Block) error {
9192
}
9293

9394
for _, nsRWSet := range rwset.NsRwSets {
94-
fmt.Printf("namespace: %v, read: %v, writes: %v\n", nsRWSet.NameSpace, nsRWSet.KvRwSet.Reads, nsRWSet.KvRwSet.Writes)
95+
// fmt.Printf("namespace: %v, read: %v, writes: %v\n", nsRWSet.NameSpace, nsRWSet.KvRwSet.Reads, nsRWSet.KvRwSet.Writes)
9596

9697
// Q: can we use Metadata?
9798
// metadataWriteSet := nsRwset.KvRwSet.MetadataWrites
9899

99100
for _, kvWrite := range nsRWSet.KvRwSet.Writes {
100101
metaData := sha256.Sum256(kvWrite.Value)
101102

102-
fmt.Printf("Saving namespace: %v, key: %v, metadata: %x\n", nsRWSet.NameSpace, kvWrite.Key, metaData)
103+
// fmt.Printf("Saving namespace: %v, key: %v, metadata: %x\n", nsRWSet.NameSpace, kvWrite.Key, metaData)
103104

104105
// Update tleState using PutMeta
105106
err := p.tleState.PutMeta(nsRWSet.NameSpace, kvWrite.Key, metaData[:])
@@ -112,7 +113,10 @@ func (p *TlePeer) UpdateState(block *common.Block) error {
112113
return nil
113114
}
114115

116+
var totalVerifyTime time.Duration
117+
115118
func (p *TlePeer) ProcessBlock(block *common.Block, blockNum int) error {
119+
tStart := time.Now()
116120
err := VerifyBlock(p.policyMgr, []byte(p.channelName), uint64(blockNum), block)
117121
if err != nil {
118122
return err
@@ -127,6 +131,8 @@ func (p *TlePeer) ProcessBlock(block *common.Block, blockNum int) error {
127131
if err != nil {
128132
return err
129133
}
134+
totalVerifyTime += time.Since(tStart)
135+
fmt.Println("total verify time:", totalVerifyTime)
130136

131137
// update state
132138
return p.UpdateState(block)
@@ -162,6 +168,7 @@ func (p *TlePeer) InitFabricPart(genesisBlock *common.Block) func() {
162168
}
163169

164170
func (p *TlePeer) Start() {
171+
totalVerifyTime = 0 * time.Second
165172
genesisBlock, err := p.blockListener.GetNextBlock()
166173
sDec, _ := base64.StdEncoding.DecodeString("AA==")
167174
genesisBlock.Metadata.Metadata[2] = sDec

tle_go/tlecore/validator.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
func VerifyBlock(channelPolicyManagerGetter policies.ChannelPolicyManagerGetter, chainID common.ChannelID, seqNum uint64, block *pcommon.Block) error {
33-
fmt.Println("start verifyBlock")
33+
// fmt.Println("start verifyBlock")
3434
if block.Header == nil {
3535
return fmt.Errorf("Invalid Block on channel [%s]. Header must be different from nil.", chainID)
3636
}
@@ -77,7 +77,9 @@ func VerifyBlock(channelPolicyManagerGetter policies.ChannelPolicyManagerGetter,
7777
// Get block validation policy
7878
policy, ok := cpm.GetPolicy(policies.BlockValidation)
7979
// ok is true if it was the policy requested, or false if it is the default policy
80-
fmt.Printf("Got block validation policy for channel [%s] with flag [%t], policy [%s]\n", channelID, ok, policy)
80+
if !ok {
81+
fmt.Printf("Got block validation policy for channel [%s] with flag [%t], policy [%s]\n", channelID, ok, policy)
82+
}
8183

8284
// - Prepare SignedData
8385
signatureSet := []*protoutil.SignedData{}
@@ -97,7 +99,7 @@ func VerifyBlock(channelPolicyManagerGetter policies.ChannelPolicyManagerGetter,
9799
}
98100

99101
// - Evaluate policy
100-
fmt.Println("Start evaluateSignedData")
102+
// fmt.Println("Start evaluateSignedData")
101103
// if len(signatureSet) > 0 {
102104
// fmt.Printf("signatureSet[0].Identity = [%x]\n", signatureSet[0].Identity)
103105
// fmt.Printf("signatureSet[0].Data = [%x]\n", signatureSet[0].Data)

0 commit comments

Comments
 (0)