diff --git a/contractmgr/contract_manager.go b/contractmgr/contract_manager.go index 627bb4ff6de74f66600283fbbd8f87140ed87650..03bfe60ebfec4adb69fae26b9b4837b6c247c57c 100644 --- a/contractmgr/contract_manager.go +++ b/contractmgr/contract_manager.go @@ -36,6 +36,7 @@ const ( // Version Compatibility 231 blockVersion231 = 2030100 blockVersion2312 = 2030102 + blockVersion235 = 2030500 ) var ( @@ -490,6 +491,11 @@ func (r *ContractManagerRuntime) upgradeContract(txSimContext protocol.TxSimCont return common.ResultSuccess(contractBytes, gas) } + if txSimContext.GetBlockVersion() >= blockVersion235 { + // 安装和升级合约交易,单独出块,不支持并行 + contract.Index++ + } + c2, result, err2 := r.upgrade(txSimContext, contract, byteCode, parameters) if err2 != nil { return common.ResultError(err2) @@ -672,7 +678,7 @@ func (r *ContractManagerRuntime) GetAllContracts(context protocol.TxSimContext) // saveContract 存储新合约 func (r *ContractManagerRuntime) saveContract(context protocol.TxSimContext, name, version string, byteCode []byte, - runTime commonPb.RuntimeType) (*commonPb.Contract, []byte, []byte, error) { + runTime commonPb.RuntimeType, index uint32) (*commonPb.Contract, []byte, []byte, error) { nameKey := utils.GetContractDbKey(name) existContract, _ := context.Get(ContractName, nameKey) if len(existContract) > 0 { //exist @@ -692,6 +698,11 @@ func (r *ContractManagerRuntime) saveContract(context protocol.TxSimContext, nam Creator: creator, } + // 这个自增的index 用来区分不同版本的合约,不再依赖用户自己定义的version字符串来做唯一标识 + if context.GetBlockVersion() >= blockVersion235 { + contract.Index = index + } + if context.GetBlockVersion() >= 2220 { //contract.Address = generateAddress(context, name) chainCfg, _ := context.GetBlockchainStore().GetLastChainConfig() @@ -750,7 +761,7 @@ func (r *ContractManagerRuntime) saveContract(context protocol.TxSimContext, nam func (r *ContractManagerRuntime) installLT2300(context protocol.TxSimContext, name, version string, byteCode []byte, runTime commonPb.RuntimeType, initParameters map[string][]byte) (*commonPb.Contract, uint64, error) { - contract, byteCodeKey, extBytecode, err := r.saveContract(context, name, version, byteCode, runTime) + contract, byteCodeKey, extBytecode, err := r.saveContract(context, name, version, byteCode, runTime, 0) if err != nil { return nil, 0, err } @@ -813,7 +824,11 @@ func differentiateErr(version uint32, rtType commonPb.RuntimeType, msg string) ( func (r *ContractManagerRuntime) install(context protocol.TxSimContext, name, version string, byteCode []byte, runTime commonPb.RuntimeType, initParameters map[string][]byte) (*commonPb.Contract, *commonPb.ContractResult, error) { - contract, byteCodeKey, extBytecode, err := r.saveContract(context, name, version, byteCode, runTime) + var contract_index uint32 + if context.GetBlockVersion() >= blockVersion235 { + contract_index = 1 + } + contract, byteCodeKey, extBytecode, err := r.saveContract(context, name, version, byteCode, runTime, contract_index) if err != nil { return nil, nil, err } diff --git a/contractmgr/contract_manger_test.go b/contractmgr/contract_manger_test.go index 663828d626023b86c50c1cef26af907aaa0fba7f..fa0358c32fe1cdc078e4d5cc3ca54a4959bf4788 100644 --- a/contractmgr/contract_manger_test.go +++ b/contractmgr/contract_manger_test.go @@ -50,7 +50,7 @@ func TestContractManagerRuntime_SaveContract(t *testing.T) { //gomock.Any()).Return(&commonPb.ContractResult{Code: 0}, protocol.ExecOrderTxTypeNormal, commonPb.TxStatusCode_SUCCESS) runtime := &ContractManagerRuntime{log: &test.GoLogger{}} result, byteCodeKey, _, err := runtime.saveContract(txSimContext, "testContractName", "v1", - []byte("bytes"), commonPb.RuntimeType_WASMER) + []byte("bytes"), commonPb.RuntimeType_WASMER, 0) assert.Nil(t, err) t.Log(result) t.Log(byteCodeKey) diff --git a/go.mod b/go.mod index e5ddb24da82c7d8b166fe10334ad897f01cf20d6..f17d21f07cb729f8b8118d0789d0506c41ccc3ef 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( chainmaker.org/chainmaker/common/v2 v2.3.4 chainmaker.org/chainmaker/localconf/v2 v2.3.4 chainmaker.org/chainmaker/logger/v2 v2.3.4 - chainmaker.org/chainmaker/pb-go/v2 v2.3.5 + chainmaker.org/chainmaker/pb-go/v2 v2.3.6-0.20240813032720-f0c611d5e15e chainmaker.org/chainmaker/protocol/v2 v2.3.5 chainmaker.org/chainmaker/utils/v2 v2.3.5 github.com/gogo/protobuf v1.3.2 diff --git a/go.sum b/go.sum index ddc3aa7241e23d7abadf9a268a118be9ce8fb885..7ba832dd25774fbbe81aa2a38b0ff9fcbb81d2b0 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,9 @@ chainmaker.org/chainmaker/localconf/v2 v2.3.4 h1:jP6V5wrbvbXoLbGXw1J2+v2TTQIqyP1 chainmaker.org/chainmaker/localconf/v2 v2.3.4/go.mod h1:lq2BcWK3YzLLADxbDLrcbWR5B6SNZQ+9IwO3dbqa8BM= chainmaker.org/chainmaker/logger/v2 v2.3.4 h1:Cxh61xj6s+V8ECrcCOPSPPtwkMCo0DQa0CTVzExlMXE= chainmaker.org/chainmaker/logger/v2 v2.3.4/go.mod h1:NdCoViHM85yoRojDHsF9+cWF1RVyNTlDN9in4PitOWY= -chainmaker.org/chainmaker/pb-go/v2 v2.3.5 h1:2PE8XJNFyBw++qUD7dIv8mgLIlHtoybz86VMOss1P8A= chainmaker.org/chainmaker/pb-go/v2 v2.3.5/go.mod h1:GXGRIYS+d6bcgmmqKrW7nNBh3mIHE1EwTLv96811OtE= +chainmaker.org/chainmaker/pb-go/v2 v2.3.6-0.20240813032720-f0c611d5e15e h1:0PM+WXHJkpc7NTl/gL37gdfTLRtDh0d1H/Hzq69BWo0= +chainmaker.org/chainmaker/pb-go/v2 v2.3.6-0.20240813032720-f0c611d5e15e/go.mod h1:GXGRIYS+d6bcgmmqKrW7nNBh3mIHE1EwTLv96811OtE= chainmaker.org/chainmaker/protocol/v2 v2.3.5 h1:OUZp596mr6uRDS0exO6D/M1WUwNdkgrrBxCKmq5NMuI= chainmaker.org/chainmaker/protocol/v2 v2.3.5/go.mod h1:UDPjfqLH89QY8FbWxfEqNcWS2W5pk/z0pU7zo1FAzyI= chainmaker.org/chainmaker/utils/v2 v2.3.5 h1:m8jZPsuQh8VhZq3R82SvCkWVzm8Dok3/7L7Bz2B/OfI=