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

Commit 0076cac1 authored by shaozhuguang's avatar shaozhuguang

Merge branch 'v2.3.5_qc_fix_contract_manage' into 'v2.3.5_qc' (merge request !280)

fix: docker go install contract with index
fix: docker go install contract with index

--story=1008374
parents 9d55765b 82a4ed4c
......@@ -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 contractIndex uint32
if context.GetBlockVersion() >= blockVersion235 {
contractIndex = 1
}
contract, byteCodeKey, extBytecode, err := r.saveContract(context, name, version, byteCode, runTime, contractIndex)
if err != nil {
return nil, nil, err
}
......
......@@ -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)
......
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