1.启动SPV轻节点
在spv/scripts目录,运行start.sh脚本,将会调用spv/build/release/bin目录中的start.sh脚本,启动SPV轻节点。
$./start.sh
查看进程是否存在
$ps-ef|grep spv|grep-v grep501 82533 1 0 12:27AM ttys011 0:00.23./spv start-c../config/spv.yml
查看端口是否监听
$lsof-i:12345 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME spv 82533 liukemeng 14u IPv4 0x321a94eae97e5edf 0t0 TCP localhost:12345(LISTEN)$lsof-i:12346 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME spv 85673 liukemeng 14u IPv4 0x425a94eae97e5edf 0t0 TCP localhost:12346(LISTEN)
查看日志
$tail-f../build/release/log/spv.log2021-06-23 00:28:02.318INFOserver/spv_server.go:88====Start SPV Server!====2021-06-23 00:28:02.340INFOmanager/state_manager.go:145[ChainId:chain1]----start chain listening and state manager!----2021-06-23 00:28:02.342INFOmanager/state_manager.go:176[ChainId:chain1]subscribe block success!2021-06-23 00:28:02.345INFOrpcserver/rpc_server.go:65 GRPC Server Listen on 127.0.0.1:123452021-06-23 00:28:02.345INFOwebserver/web_server.go:85 Web Server Listen on HTTP 127.0.0.1:123462021-06-23 00:28:12.414INFOmanager/block_manager.go:167[ChainId:chain1]spv has synced to the highest block!current local height:0,remote max height:0
2.停止SPV轻节点
在spv/scripts目录,运行stop.sh脚本,将会调用spv/build/release/bin目录中的stop.sh脚本,停止SPV轻节点。
$./stop.sh
3.停止SPV轻节点并清除data和log
在spv/scripts目录,运行stop.sh脚本,并添加clean命令,将会调用spv/build/release/bin目录中的stop.sh脚本,停止SPV轻节点,并清除spv/build/release/data中的所有数据。
$./stop.sh clean
3.SPV模式独立部署时,Client端通过grpc验证交易有效性示例
package usecaseimport("context""log""chainmaker.org/chainmaker/spv/v2/pb/api""google.golang.org/grpc")func useCase(){//1.构造Client conn,err:=grpc.Dial("127.0.0.1:12308",grpc.WithInsecure())if err!=nil{log.Fatal(err)return}client:=api.NewRpcProverClient(conn)//2.构造交易验证信息request:=&api.TxValidationRequest{ChainId:"chainId",//链Id BlockHeight:1,
//交易所在区块高度//Index:-1,//此版本未验证该字段,不需要填写TxKey:"TxId",//交易Id ContractData:&api.ContractData{Name:"contractName",//合约名Method:"method",//方法名Version:"version",
//合约版本Params:[]*api.KVPair{{Key:"argName1",Value:[]byte("argValue1")},//Key是所调用合约方法的参数名,Value是参数值{Key:"argName2",Value:[]byte("argValue2")},{Key:"argName3",Value:[]byte("argValue3")},},Extra:nil,//预留扩展字段},Timeout:5000,//验证超时时间Extra:nil,//预留扩展字段}//3.验证交易有效性response,err:=client.ValidTransaction(context.Background(),request)if err!=nil{log.Fatal(err)}if int32(response.Code)!=0{log.Fatal(err)}//4.用户其他逻辑}