新注册的用户请输入邮箱并保存,随后登录邮箱激活账号。后续可直接使用邮箱登录!

Commit f834110d authored by nz wei's avatar nz wei

fix: docker go install contract with index

--story=1008374
parent 9d55765b
...@@ -36,6 +36,7 @@ const ( ...@@ -36,6 +36,7 @@ const (
// Version Compatibility 231 // Version Compatibility 231
blockVersion231 = 2030100 blockVersion231 = 2030100
blockVersion2312 = 2030102 blockVersion2312 = 2030102
blockVersion235 = 2030500
) )
var ( var (
...@@ -490,6 +491,11 @@ func (r *ContractManagerRuntime) upgradeContract(txSimContext protocol.TxSimCont ...@@ -490,6 +491,11 @@ func (r *ContractManagerRuntime) upgradeContract(txSimContext protocol.TxSimCont
return common.ResultSuccess(contractBytes, gas) return common.ResultSuccess(contractBytes, gas)
} }
if txSimContext.GetBlockVersion() >= blockVersion235 {
// 安装和升级合约交易,单独出块,不支持并行
contract.Index++
}
c2, result, err2 := r.upgrade(txSimContext, contract, byteCode, parameters) c2, result, err2 := r.upgrade(txSimContext, contract, byteCode, parameters)
if err2 != nil { if err2 != nil {
return common.ResultError(err2) return common.ResultError(err2)
...@@ -672,7 +678,7 @@ func (r *ContractManagerRuntime) GetAllContracts(context protocol.TxSimContext) ...@@ -672,7 +678,7 @@ func (r *ContractManagerRuntime) GetAllContracts(context protocol.TxSimContext)
// saveContract 存储新合约 // saveContract 存储新合约
func (r *ContractManagerRuntime) saveContract(context protocol.TxSimContext, name, version string, byteCode []byte, 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) nameKey := utils.GetContractDbKey(name)
existContract, _ := context.Get(ContractName, nameKey) existContract, _ := context.Get(ContractName, nameKey)
if len(existContract) > 0 { //exist if len(existContract) > 0 { //exist
...@@ -692,6 +698,11 @@ func (r *ContractManagerRuntime) saveContract(context protocol.TxSimContext, nam ...@@ -692,6 +698,11 @@ func (r *ContractManagerRuntime) saveContract(context protocol.TxSimContext, nam
Creator: creator, Creator: creator,
} }
// 这个自增的index 用来区分不同版本的合约,不再依赖用户自己定义的version字符串来做唯一标识
if context.GetBlockVersion() >= blockVersion235 {
contract.Index = index
}
if context.GetBlockVersion() >= 2220 { if context.GetBlockVersion() >= 2220 {
//contract.Address = generateAddress(context, name) //contract.Address = generateAddress(context, name)
chainCfg, _ := context.GetBlockchainStore().GetLastChainConfig() chainCfg, _ := context.GetBlockchainStore().GetLastChainConfig()
...@@ -750,7 +761,7 @@ func (r *ContractManagerRuntime) saveContract(context protocol.TxSimContext, nam ...@@ -750,7 +761,7 @@ func (r *ContractManagerRuntime) saveContract(context protocol.TxSimContext, nam
func (r *ContractManagerRuntime) installLT2300(context protocol.TxSimContext, name, version string, byteCode []byte, func (r *ContractManagerRuntime) installLT2300(context protocol.TxSimContext, name, version string, byteCode []byte,
runTime commonPb.RuntimeType, initParameters map[string][]byte) (*commonPb.Contract, uint64, error) { 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 { if err != nil {
return nil, 0, err return nil, 0, err
} }
...@@ -813,7 +824,11 @@ func differentiateErr(version uint32, rtType commonPb.RuntimeType, msg string) ( ...@@ -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, func (r *ContractManagerRuntime) install(context protocol.TxSimContext, name, version string, byteCode []byte,
runTime commonPb.RuntimeType, initParameters map[string][]byte) (*commonPb.Contract, *commonPb.ContractResult, error) { 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 { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
...@@ -50,7 +50,7 @@ func TestContractManagerRuntime_SaveContract(t *testing.T) { ...@@ -50,7 +50,7 @@ func TestContractManagerRuntime_SaveContract(t *testing.T) {
//gomock.Any()).Return(&commonPb.ContractResult{Code: 0}, protocol.ExecOrderTxTypeNormal, commonPb.TxStatusCode_SUCCESS) //gomock.Any()).Return(&commonPb.ContractResult{Code: 0}, protocol.ExecOrderTxTypeNormal, commonPb.TxStatusCode_SUCCESS)
runtime := &ContractManagerRuntime{log: &test.GoLogger{}} runtime := &ContractManagerRuntime{log: &test.GoLogger{}}
result, byteCodeKey, _, err := runtime.saveContract(txSimContext, "testContractName", "v1", result, byteCodeKey, _, err := runtime.saveContract(txSimContext, "testContractName", "v1",
[]byte("bytes"), commonPb.RuntimeType_WASMER) []byte("bytes"), commonPb.RuntimeType_WASMER, 0)
assert.Nil(t, err) assert.Nil(t, err)
t.Log(result) t.Log(result)
t.Log(byteCodeKey) t.Log(byteCodeKey)
......
...@@ -6,8 +6,9 @@ chainmaker.org/chainmaker/localconf/v2 v2.3.4 h1:jP6V5wrbvbXoLbGXw1J2+v2TTQIqyP1 ...@@ -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/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 h1:Cxh61xj6s+V8ECrcCOPSPPtwkMCo0DQa0CTVzExlMXE=
chainmaker.org/chainmaker/logger/v2 v2.3.4/go.mod h1:NdCoViHM85yoRojDHsF9+cWF1RVyNTlDN9in4PitOWY= 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.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 h1:OUZp596mr6uRDS0exO6D/M1WUwNdkgrrBxCKmq5NMuI=
chainmaker.org/chainmaker/protocol/v2 v2.3.5/go.mod h1:UDPjfqLH89QY8FbWxfEqNcWS2W5pk/z0pU7zo1FAzyI= 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= chainmaker.org/chainmaker/utils/v2 v2.3.5 h1:m8jZPsuQh8VhZq3R82SvCkWVzm8Dok3/7L7Bz2B/OfI=
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment