首页 \ 问答 \ 如何设计hyperledger链代码以适合您的业务?(how to design your chaincode of hyperledger to fit for your business?)

如何设计hyperledger链代码以适合您的业务?(how to design your chaincode of hyperledger to fit for your business?)

我正在关注链码开发指南: https//github.com/hyperledger/fabric/blob/07ea01124b2768ee04a6b30fe29a6395f6d3d819/docs/API/SandboxSetup.md

使用我的测试结果,在生产环境(不是开发环境,而不是--peer-chaincodedev)中,deploy方法的工作负载(如系统运行时和存储大小)远高于invoke方法。

如果测试结果是正确的,我认为部署方法的成本远高于调用方法。 超过1,000,000倍的成本。

在这样的成本情况下,我们应该做什么样的设计? 频率如何适合。

例如,我们应该如何避免调用deploy方法? 我们应该如何使用invoke方法替换deploy方法?


I am following chaincode development guide : https://github.com/hyperledger/fabric/blob/07ea01124b2768ee04a6b30fe29a6395f6d3d819/docs/API/SandboxSetup.md

With my test result, in production environment (not development environment, not --peer-chaincodedev ), the work load (such as system run time and storage size) of deploy method are much higher than invoke method.

If the test result is correct, I imagine the cost of deploy method are much higher than invoke method. more than 1,000,000 times of cost.

In such cost situation, what kinds of design should we do? how frequency is suitable.

for example, how should we avoid to call deploy method? how should we use invoke method to replace deploy method?


原文:https://stackoverflow.com/questions/37570667
更新时间:2019-12-13 07:40

最满意答案

  1. 部署一次,chaincode名称是更好的业务名称,而不是您的进程名称的情况。

func (t *Chaincode) Init(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
	var err error
	var Number string
	if len(args) != 1 {return nil, errors.New("sign Init Expecting 1 number of arguments.")}
	Number = args[0]
	err = stub.PutState(Number, []byte("01"))
	if err != nil {return nil, err}

	return nil, nil
}

  1. 使用invoke方法来避免新链代码的部署方法。

func (t *Chaincode) Invoke(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
	if function == "delete" {
		// Deletes an entity from its state
		return t.delete(stub, args)
	}
	
	if function == "newcontract" {
		// Deletes an entity from its state
		return t.delete(stub, args)
	}
	
	xxxxxxxxxxxxxxxxxxxx
	return nil, nil
}

func (t *SimpleChaincode) Query(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
	if function != "query" {
		return nil, errors.New("Invalid query function name. Expecting \"query\"")
	}
	
	xxxxxxxxxxxxxxxxxxxx
	return xxx, nil
}

// Deletes an entity from state

func (t *SimpleChaincode) delete(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
	if len(args) != 1 {
		return nil, errors.New("Incorrect number of arguments. Expecting 1")
	}

	A := args[0]

	// Delete the key from the state in ledger
	err := stub.DelState(A)
	if err != nil {
		return nil, errors.New("Failed to delete state")
	}

	return nil, nil
}


  1. deploy once, chaincode name is better business name, not your case of process name.

func (t *Chaincode) Init(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
	var err error
	var Number string
	if len(args) != 1 {return nil, errors.New("sign Init Expecting 1 number of arguments.")}
	Number = args[0]
	err = stub.PutState(Number, []byte("01"))
	if err != nil {return nil, err}

	return nil, nil
}

  1. use invoke method to avoid deploy method of new chaincode.

func (t *Chaincode) Invoke(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
	if function == "delete" {
		// Deletes an entity from its state
		return t.delete(stub, args)
	}
	
	if function == "newcontract" {
		// Deletes an entity from its state
		return t.delete(stub, args)
	}
	
	xxxxxxxxxxxxxxxxxxxx
	return nil, nil
}

func (t *SimpleChaincode) Query(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
	if function != "query" {
		return nil, errors.New("Invalid query function name. Expecting \"query\"")
	}
	
	xxxxxxxxxxxxxxxxxxxx
	return xxx, nil
}

// Deletes an entity from state

func (t *SimpleChaincode) delete(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
	if len(args) != 1 {
		return nil, errors.New("Incorrect number of arguments. Expecting 1")
	}

	A := args[0]

	// Delete the key from the state in ledger
	err := stub.DelState(A)
	if err != nil {
		return nil, errors.New("Failed to delete state")
	}

	return nil, nil
}

2016-08-03

相关问答

更多

如何减少android SQLite中的自动增量_id?(How to decrease the Auto increment _id in android SQLite?)

编辑:也许我应该说清楚只是插入具有正确id的行而不是操纵序列号肯定比下面的方法更好。 如果表中没有id = 3的行,则即使在AUTOINCREMENT表中也可以在id中插入固定值。 也就是说,如果您确定 ,可以使用自动增量值设置为任意值; UPDATE sqlite_sequence set seq=<next sequence no -1> where name=<table name>; 也就是说,如果你想在表'TableA'上的下一个插入中使用AUTOINCREMENT来生成5,那么你可

JSON Jquery For Loop(JSON Jquery For Loop)

假设你有这个HTML <ul id="navigation"></ul> 你的JS应该像:: var Obj = { "alsotaking":[ ["bla","Software Engineering",1], ["bla","Mobile Applications",11], ["bla","Practical Networks",71], ["bla","Digital Forensics",53] ] }; function readObjA

脚本拼图

最新问答

更多
  • NumPy标量,广播和__iadd__方法(NumPy scalars, broadcasting and the __iadd__ method)
  • 快速排序算法输出错误(Getting wrong output for quicksort algorithm)
  • Rails管理员:没有Rails 4应用程序的编辑,显示或删除按钮(Rails Admin: No edit, show, or delete buttons for Rails 4 app)
  • 部分刷新问题触发两次(Issue with partial refresh triggered twice)
  • jsPlumb draggable element javascript函数(jsPlumb draggable element javascript function)
  • MVC4:ViewModel(带有radiobuttonlist)在HttpPost之后为空(MVC4: ViewModel (with radiobuttonlist) is empty after HttpPost)
  • 如何在同一帐户上设置“Dev repo”(在prod和团队之间)(How to set up a “Dev repo” (between the prod and the team) on the same account)
  • 如何在tcl中将eth0配置为发送方udp端口(how to configure eth0 as a sender udp port in tcl)
  • EF6.1 beta 1如何获得Tooling Consolidation功能?(EF6.1 beta 1 how to get the Tooling Consolidation feature?)
  • 适用于Windows和PHP 5.5的Phalcon(Phalcon for Windows and PHP 5.5)
  • 有没有办法忽略hg责任中的提交?(Is there a way to ignore a commit in hg blame?)
  • Desire2通过API学习访问学期的权限(Desire2Learn Permissions to Access Semesters Via API)
  • 从aspx将服务器的文件复制到另一台服务器(Copy a file of a server to another server from aspx)
  • 使用YSlow / Web Developer扩展程序确定页面大小(Figuring out page size with YSlow / Web Developer extension)
  • Select语句将字符串中的前7个字符与其他表中的其他7个字符进行比较(Select statement which compares first 7 chars in a string with other 7 chars in other table)
  • 检测对注册表的更改,防止更改等(Detect changes to registry, prevent changes, etc)
  • 用户的鼠标/键盘运动分析是否有特殊名称?(Does the analysis of mouse/keyboard motions of a user have a special name?)
  • 获取Rails中资源的路由列表(Get list of routes for a resource in Rails)
  • 用函数值除以数字(Divide a function value by a number)
  • 熊猫Python:如何从今天开始创建失效列?(Pandas Python: How to create lapse since today column?)
  • GDK Bug报告(GDK Bug Reports)
  • 困惑于在python中循环遍历列表(confused about looping through lists in python)
  • 'less'由'which'输出指定的文件('less' the file specified by the output of 'which')
  • 如何在ASP.NET中优化AJAX(How to optimize AJAX in ASP.NET)
  • 在文本文件中转换纪元时间(Convert epoch times in text file)
  • 表细胞伸展(Table cell stretching)
  • GridView控件(GridView Control)
  • 从构建定义文件控制pdb文件输出(Control pdb file output from build defintion file)
  • *将方法传递给类(*Passing a Method into a Class)
  • 如何在HttpReceiveHttpRequest()中使用HTTPS?(How to use HTTPS with HttpReceiveHttpRequest()?)