Skip to content

Commit 89826e8

Browse files
committed
merge block listener and run in ego
1 parent 63dca5f commit 89826e8

File tree

16 files changed

+276
-48
lines changed

16 files changed

+276
-48
lines changed

ecc_go/chaincode/enclave_go/tle_stub.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (s *TleStubInterface) GetMeta(key string) ([]byte, error) {
8888
response, err := client.GetMeta(context.Background(), request)
8989
if err != nil {
9090
log.Fatalf("Failed to call GetMeta: %v", err)
91+
return nil, err
9192
}
9293

9394
// Process the response

tle_go/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ details.env
77
tmpBlocks/
88
externalbuilder/
99
lifecycle/
10+
msp/

tle_go/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ ENV SGX_MODE=${SGX_MODE}
2020
ARG OE_SIMULATION
2121
ENV OE_SIMULATION=${OE_SIMULATION}
2222

23+
ENV MSP_PATH="/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/"
24+
COPY msp ${MSP_PATH}
25+
2326
ARG CAAS_PORT=50051
2427
ARG CC_PATH="/usr/local/bin"
2528

2629
ENV CORE_CONFIG_PATH="/usr/local/bin/core.yaml"
2730
COPY core.yaml ${CORE_CONFIG_PATH}
2831

32+
ENV ORDERER_CONFIC_PATH="/usr/local/bin/orderer.yaml"
33+
COPY orderer.yaml ${ORDERER_CONFIC_PATH}
34+
2935
ENV DEV_PATH="/usr/local/bin/sampleconfig"
3036
COPY sample-fabric-config ${DEV_PATH}
3137

tle_go/build.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ EGO_CONFIG_FILE ?= $(FPC_PATH)/tle_go/enclave.json
1717
TLE_BINARY ?= tle
1818
TLE_BUNDLE ?= $(TLE_BINARY)-bundle
1919

20-
build: ecc docker env
20+
build: copy_msp ecc docker env
21+
22+
copy_msp:
23+
rm -r msp
24+
cp -r /project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp msp
2125

2226
ecc: ecc_dependencies
2327
ego-go build $(GOTAGS) -o $(TLE_BINARY) main.go

tle_go/enclave.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,38 @@
1919
{
2020
"target": "/tmp",
2121
"type": "memfs"
22+
},
23+
{
24+
"source": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp",
25+
"target": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp",
26+
"type": "hostfs"
27+
},
28+
{
29+
"source": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/signcerts",
30+
"target": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/signcerts",
31+
"type": "hostfs"
2232
}
2333
],
2434
"files": [
2535
{
2636
"source": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/peers/Org1.Org1_peer_0/core.yaml",
2737
"target": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/peers/Org1.Org1_peer_0/core.yaml"
38+
},
39+
{
40+
"source": "/project/src/github.com/hyperledger/fabric-private-chaincode/tle_go/orderer.yaml",
41+
"target": "orderer.yaml"
42+
},
43+
{
44+
"source": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ca-certs.pem",
45+
"target": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ca-certs.pem"
46+
},
47+
{
48+
"source": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/signcerts/orderer.example.com-cert.pem",
49+
"target": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/signcerts/orderer.example.com-cert.pem"
50+
},
51+
{
52+
"source": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem",
53+
"target": "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem"
2854
}
2955
],
3056
"env": [

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-20230622161334-eae14fa46d72
17+
replace github.com/hyperledger/fabric => github.com/Flamewind97/fabric v0.0.0-20230727155655-d2a858c57147
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-20230622161334-eae14fa46d72 h1:pRxs2eWoMqblHrvnWrB1wl9erekMLTM0CarUdE+foek=
10-
github.com/Flamewind97/fabric v0.0.0-20230622161334-eae14fa46d72/go.mod h1:RTJcHdhOrpiAqZLNkpVSoz/yaxW/Wiy7sCw/zYO4LjY=
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=
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=
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tlecore
1+
package listener
22

33
import (
44
"fmt"
@@ -8,7 +8,6 @@ import (
88
"strconv"
99
"time"
1010

11-
"github.com/hyperledger/fabric-private-chaincode/tle_go/listener"
1211
"github.com/hyperledger/fabric-protos-go/common"
1312
"github.com/hyperledger/fabric/protoutil"
1413
)
@@ -68,15 +67,15 @@ type OrdererBlockGetter struct {
6867
nextBlockNum int
6968
}
7069

71-
func NewOrdererBlockGetter() BlockListener {
72-
channelID := "testchannel"
73-
serverAddr := "127.0.0.1:20000"
70+
func NewOrdererBlockGetter(channelID, serverAddr, caCertPath string) BlockListener {
71+
// channelID := "testchannel"
72+
// serverAddr := "127.0.0.1:20000"
7473
seek := -2 // -2 is load from oldest, -1 load from newest, other int -> load from the int.
7574
quiet := true // true = only print block number, false = print whole block.
76-
caCertPath := "/Users/lew/go/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ca-certs.pem"
75+
// caCertPath := "/Users/lew/go/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ca-certs.pem"
7776
blockChan := make(chan common.Block, 1)
7877

79-
go listener.ListenBlock(channelID, serverAddr, seek, quiet, caCertPath, blockChan)
78+
go ListenBlock(channelID, serverAddr, seek, quiet, caCertPath, blockChan)
8079

8180
return &OrdererBlockGetter{
8281
blockChan: blockChan,

tle_go/listener/listener.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ func ListenBlock(channelID string, serverAddr string, seek int, quiet bool, caCe
107107
fmt.Println("Failed to load MSP config:", err)
108108
os.Exit(0)
109109
}
110-
fmt.Println("mspConfig:", mspConfig)
111-
fmt.Println("factoryGetDefault:", factory.GetDefault())
110+
// fmt.Println("mspConfig:", mspConfig)
112111
err = mspmgmt.GetLocalMSP(factory.GetDefault()).Setup(mspConfig)
113112
if err != nil { // Handle errors reading the config file
114113
fmt.Println("Failed to initialize local MSP:", err)
@@ -167,7 +166,7 @@ func main() {
167166
seek := -2 // -2 is load from oldest, -1 load from newest, other int -> load from the int.
168167
quiet := false // ture = only print block number, false = print whole block.
169168
caCertPath := "/Users/lew/go/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ca-certs.pem"
170-
blockChan := make(chan cb.Block, 10)
169+
blockChan := make(chan cb.Block, 1)
171170

172171
ListenBlock(channelID, serverAddr, seek, quiet, caCertPath, blockChan)
173172
}

tle_go/main.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/hyperledger/fabric-private-chaincode/tle_go/listener"
89
"github.com/hyperledger/fabric-private-chaincode/tle_go/tlecore"
10+
tleconfig "github.com/hyperledger/fabric-private-chaincode/tle_go/tlecore/config"
911
)
1012

1113
func readConfig() {
@@ -18,17 +20,30 @@ func readConfig() {
1820
} else {
1921
configPath = os.Getenv("CORE_CONFIG_PATH")
2022
}
21-
tlecore.SetupConfig(configPath)
23+
tleconfig.SetupConfig(configPath)
2224
}
2325

2426
func main() {
25-
fmt.Println("--- in TLE_go main.go start to create grpc server.---")
26-
readConfig()
27-
28-
tlestate := &tlecore.Tlestate{}
2927

3028
// serve block listener.
31-
go tlecore.ServePeer(tlestate)
29+
channelID := "testchannel"
30+
serverAddr := "host.docker.internal:20000"
31+
caCertPath := "/project/src/github.com/hyperledger/fabric-private-chaincode/samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ca-certs.pem"
32+
// if fpc_path exist, which mean it is running in local machine.
33+
fpcPath := os.Getenv("FPC_PATH")
34+
if fpcPath != "" {
35+
serverAddr = "127.0.0.1:20000"
36+
caCertPath = filepath.Join(fpcPath, "samples/deployment/fabric-smart-client/the-simple-testing-network/testdata/fabric.default/crypto/ca-certs.pem")
37+
}
38+
blockListener := listener.NewOrdererBlockGetter(channelID, serverAddr, caCertPath)
39+
// blockListener := listener.NewFileBlockGetter()
40+
fmt.Scanln()
41+
42+
// fmt.Println("--- in TLE_go main.go start to create grpc server.---")
43+
44+
readConfig()
45+
tlestate := &tlecore.Tlestate{}
46+
go tlecore.ServePeer(tlestate, blockListener)
3247

3348
// serve metadata service.
3449
tlecore.ServeMeta("0.0.0.0:50051", tlestate)

0 commit comments

Comments
 (0)