Skip to content
Closed
8 changes: 6 additions & 2 deletions bcs/consensus/xpoa/xpoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func NewXpoaConsensus(cCtx cctx.ConsensusCtx, cCfg def.ConsensusConfig) base.Con
cCtx.XLog.Error("consensus:xpoa:NewXpoaConsensus: xpoa struct unmarshal error", "error", err)
return nil
}
//兼容老版本配置文件
if len(xconfig.Version) < 1 {
xconfig.Version = "0"
}
version, err := strconv.ParseInt(xconfig.Version, 10, 64)
if err != nil {
cCtx.XLog.Error("consensus:xpoa:NewXpoaConsensus: version error", "error", err)
Expand Down Expand Up @@ -232,7 +236,7 @@ func (x *xpoaConsensus) CheckMinerMatch(ctx xcontext.XContext, block cctx.BlockI
// 包装成统一入口访问smr
err = x.smr.CheckProposal(block, justify, validators)
if err != nil {
x.log.Error("consensus:tdpos:CheckMinerMatch: bft IsQuorumCertValidate failed", "proposalQC:[height]", block.GetHeight(),
x.log.Error("consensus:xpoa:CheckMinerMatch: bft IsQuorumCertValidate failed", "proposalQC:[height]", block.GetHeight(),
"proposalQC:[id]", utils.F(block.GetBlockid()), "justifyQC:[height]", justify.GetProposalView(),
"justifyQC:[id]", utils.F(justify.GetProposalId()), "error", err)
return false, err
Expand Down Expand Up @@ -264,7 +268,7 @@ func (x *xpoaConsensus) ProcessBeforeMiner(timestamp int64) ([]byte, []byte, err
}
// 重做时还需要装载标定节点TipHeight,复用TargetBits作为回滚记录,便于追块时获取准确快照高度
if truncate {
x.log.Warn("consensus:tdpos:ProcessBeforeMiner: last block not confirmed, walk to previous block",
x.log.Warn("consensus:xpoa:ProcessBeforeMiner: last block not confirmed, walk to previous block",
"target", utils.F(qc.GetProposalId()), "ledger", tipBlock.GetHeight())
storage.TargetBits = int32(tipBlock.GetHeight())
bytes, _ := json.Marshal(storage)
Expand Down
35 changes: 35 additions & 0 deletions bcs/ledger/xledger/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package state
import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/big"
Expand Down Expand Up @@ -911,6 +912,40 @@ func (t *State) QueryBlock(blockid []byte) (kledger.BlockHandle, error) {
return NewBlockAgent(block), nil

}

func (t *State) ResolveChain(chainName string) (*pb2.CrossQueryMeta, error) {
xmReader := t.CreateXMReader()
sandBoxCfg := &contract.SandboxConfig{
XMReader: xmReader,
}
sandBox, err := t.sctx.ContractMgr.NewStateSandbox(sandBoxCfg)
if err != nil {
return nil, err
}
contextConfig := &contract.ContextConfig{
State: sandBox,
ResourceLimits: contract.MaxLimits,
ContractName: "crossQueryNaming",
}

ctx, err := t.sctx.ContractMgr.NewContext(contextConfig)
if err != nil {
t.log.Warn("queryContractBannedStatus new context error", "error", err)
return nil, err
}
args := map[string][]byte{}
args["name"] = []byte(chainName)
invokeRes, invokeErr := ctx.Invoke("Resolve", args)
if invokeErr != nil {
ctx.Release()
return nil, invokeErr
}
ctx.Release()
res := &pb2.CrossQueryMeta{}
err = json.Unmarshal(invokeRes.Body, res)
return res, err
}

func (t *State) QueryTransaction(txid []byte) (*pb2.Transaction, error) {
ltx, err := t.sctx.Ledger.QueryTransaction(txid)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions bcs/network/p2pv1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net"
"strings"
"time"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -142,6 +143,12 @@ func (p *P2PServerV1) serve() {
panic(fmt.Sprintf("address error: address=%s", err))
}

//Compatible container runtime, listening ":port"
portIndex := strings.LastIndex(ip, ":")
if portIndex > 0 {
ip = ip[portIndex:]
}

l, err := net.Listen(network, ip)
if err != nil {
panic(err)
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ module github.com/xuperchain/xupercore
go 1.14

require (
github.com/ChainSafe/go-schnorrkel v0.0.0-20200626160457-b38283118816 // indirect
github.com/aws/aws-sdk-go v1.32.4
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
github.com/dgraph-io/badger/v3 v3.2103.1
github.com/docker/go-connections v0.4.1-0.20180821093606-97c2040d34df // indirect
github.com/docker/go-units v0.4.0
github.com/emirpasic/gods v1.12.1-0.20201118132343-79df803e554c
github.com/fsouza/go-dockerclient v1.6.0
github.com/gammazero/deque v0.1.0
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.4.3
github.com/golang/snappy v0.0.3
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/grpc-ecosystem/grpc-gateway v1.9.0
github.com/hashicorp/golang-lru v0.5.4
github.com/hyperledger/burrow v0.30.5
github.com/ipfs/go-ipfs-addr v0.0.1
Expand All @@ -33,12 +31,16 @@ require (
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.6.2
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca
github.com/tjfoc/gmsm v1.4.1
github.com/xuperchain/crypto v0.0.0-20201028025054-4d560674bcd6
github.com/xuperchain/log15 v0.0.0-20190620081506-bc88a9198230
github.com/xuperchain/xvm v0.0.0-20210126142521-68fd016c56d7
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.35.0
google.golang.org/protobuf v1.25.0

)

replace github.com/hyperledger/burrow => github.com/xuperchain/burrow v0.30.6-0.20210317023017-369050d94f4a
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmg
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 h1:FlFbCRLd5Jr4iYXZufAvgWN6Ao0JrI5chLINnUXDDr0=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0 h1:bM6ZAFZmc/wPFaRDi0d5L7hGEZEx/2u+Tmr2evNHDiI=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f h1:8N8XWLZelZNibkhM1FuF+3Ad3YIbgirjdMiVA0eUkaM=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down
7 changes: 7 additions & 0 deletions kernel/consensus/mock/mock_pluggable_consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ func (c *FakeKContext) QueryBlock(blockid []byte) (*xldgpb.InternalBlock, error)
func (c *FakeKContext) QueryTransaction(txid []byte) (*pb.Transaction, error) {
return &pb.Transaction{}, nil
}
func (c *FakeKContext) CrossQuery(crossQueryRequest *pb.CrossQueryRequest, queryMeta *pb.CrossQueryMeta) (*pb.ContractResponse, error) {
return nil, nil
}

type FakeManager struct {
R *FakeRegistry
Expand All @@ -384,6 +387,10 @@ func (m *FakeManager) GetKernRegistry() contract.KernRegistry {
return m.R
}

func (m *FakeManager) CrossQuery(crossQueryRequest *pb.CrossQueryRequest, queryMeta *pb.CrossQueryMeta) (*pb.ContractResponse, error) {
return nil, nil
}

type FakeRegistry struct {
M map[string]contract.KernMethod
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/consensus/pluggable_consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestUpdateConsensus(t *testing.T) {
return
}
fakeCtx := mock.NewFakeKContext(NewUpdateArgs(), NewUpdateM())
np.updateConsensus(fakeCtx)
//np.updateConsensus(fakeCtx)
if len(np.stepConsensus.cons) != 2 {
t.Error("Update consensus error!")
return
Expand Down
113 changes: 113 additions & 0 deletions kernel/contract/bridge/cross_uri.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package bridge

import (
"fmt"
"net/url"

"github.com/xuperchain/xupercore/kernel/contract/bridge/pb"
)

const (
// XuperScheme define the xuper scheme
XuperScheme = "xuper"
)

// CrossChainURI Standard
// [scheme:][//chain_name][path][?query]
// eg xuper://chain1?module=wasm&bcname=xuper&contract_name=counter&method_name=increase
type CrossChainURI struct {
*url.URL
}

// ParseCrossChainURI will parse uri to cross chain uri instance
func ParseCrossChainURI(crossChainURI string) (*CrossChainURI, error) {
uri, err := url.Parse(crossChainURI)
if err != nil {
return nil, err
}

return &CrossChainURI{
uri,
}, nil
}

// GetScheme return cross chain uri scheme
func (ccu *CrossChainURI) GetScheme() string {
return ccu.URL.Scheme
}

// GetChainName return cross chain uri chain name
func (ccu *CrossChainURI) GetChainName() string {
return ccu.URL.Host
}

// GetPath return cross chain uri path
func (ccu *CrossChainURI) GetPath() string {
return ccu.URL.Path
}

// GetQuery return cross chain uri query
func (ccu *CrossChainURI) GetQuery() url.Values {
return ccu.URL.Query()
}

// CrossChainScheme define the interface of CrossChainScheme
type CrossChainScheme interface {
GetName() string
GetCrossQueryRequest(*CrossChainURI, []*pb.ArgPair, string, []string) (*pb.CrossQueryRequest, error)
}

// CrossXuperScheme define the xuper scheme
type CrossXuperScheme struct {
}

// GetCrossQueryRequest return XupeScheme instance with CrossChainURI
// [scheme:][//chain_name][?query]
// eg xuper://chain1?module=wasm&bcname=xuper&contract_name=counter&method_name=increase
func (cxs *CrossXuperScheme) GetCrossQueryRequest(crossChainURI *CrossChainURI,
argPair []*pb.ArgPair, initiator string, authRequire []string) (*pb.CrossQueryRequest, error) {
if initiator == "" {
return nil, fmt.Errorf("GetCrossQueryRequest initiator is nil")
}

querys := crossChainURI.GetQuery()
module := querys.Get("module")
bcname := querys.Get("bcname")
contractName := querys.Get("contract_name")
methodName := querys.Get("method_name")
if module == "" || bcname == "" || contractName == "" || methodName == "" {
return nil, fmt.Errorf("GetCrossQueryRequest query is nil")
}
args := make(map[string][]byte)
for _, arg := range argPair {
args[arg.GetKey()] = arg.GetValue()
}

crossQueryRequest := &pb.CrossQueryRequest{
Bcname: bcname,
Initiator: initiator,
AuthRequire: authRequire,
Request: &pb.InvokeRequest{
ModuleName: module,
ContractName: contractName,
MethodName: methodName,
Args: args,
},
}
return crossQueryRequest, nil
}

// GetName return cross xuper scheme name
func (cxs *CrossXuperScheme) GetName() string {
return XuperScheme
}

// GetChainScheme return chain scheme by scheme
func GetChainScheme(scheme string) CrossChainScheme {
switch scheme {
case XuperScheme:
return &CrossXuperScheme{}
default:
return &CrossXuperScheme{}
}
}
Loading