我正在尝试使用Go中的AWS SDK将记录插入QLDB分类账。我以PythonQLDB驱动程序为例,记录了在那里生成的最终事务哈希。这在事务提交期间用于与QLDB端生成的哈希进行比较,以验证事务并允许它提交,python驱动程序成功地完成了这项工作
不过,目前还没有一个Go版本的IonHash,因此我在Go中实现了StartTransaction、InsertInto和CommitTransaction步骤,并包含了一个Python可执行IonHash实现,用于计算最后用于比较摘要的IonHash
// Go (pseudocode)
import "github.com/fernomac/ion-go" as ion
import python_hash_module as python
func (client qldbClient) StartTransaction(transactionID string) {
// hash transactionID using python ionhash
}
func (client) InsertInto (statement string, params string) {
// MarshalText using ion module in aws-sdk
ionParam := ion.MarshalText(params)
// hash statement using python executable
client.statementHash = python.ion_hash(statement)
// hash parameters using python executable (only one parameter)
client.paramHash = python.ion_hash(ionParam)
// dot paramHash with statement hash
client.statementHash = client.statementHash.dot(client.paramHash)
// dot statement hash with transactionhash - this transaction hash matches the python calculation!
client.transactionHash = client.transactionHash.dot(statementHash)
}
func (client) Commit() {
res, err := client.execute(statement) // compares calculated transaction hash with AWS calculated transaction hash
if err != nil {
log.Prinln(err)
}
代码在提交步骤中失败,出现以下错误:
{
Code_: "412",
Message_: "Digests don't match"
}
2020/03/22 11:16:41 xxxx.go:xxx: BadRequestException: Digests don't match
{
Code_: "412",
Message_: "Digests don't match"
}
我不明白为什么在go中提交时,这些摘要不匹配,而这个实现正在生成与python代码相同的摘要,而python代码正在提交。为什么python代码在生成与go代码相同的提交时不抱怨摘要不匹配?更重要的是,如何通过Go(而不是python或节点驱动程序)成功插入QLDB
离子散列go不可用的理解是正确的
在计算哈希时,您可能需要检查以下几项:
从您的伪代码中我可以猜到您可能缺少1)和2)。更具体地说,我的意思是,伪代码表明哈希没有使用事务id作为种子,并且点运算符没有按正确的顺序应用于哈希
有关QLDB哈希计算的更多详细信息,请参阅Marc的答案-How to get/compute CommitDigest when committing a transaction in AWS QLDB?
愿意在这方面进一步提供帮助
更新:
离子散列go现在可用-https://github.com/amzn/ion-hash-go
还发布了与QLDB交互的go驱动程序-https://github.com/awslabs/amazon-qldb-driver-go
它们目前都是测试版
不确定这是否仍然有用,但Amazon最近发布了QLDB Go驱动程序的预览版本(https://github.com/awslabs/amazon-qldb-driver-go)
它的依赖项是Ion和Ion Hash,因此这将使您在使用QLDB时更加容易
相关问题 更多 >
编程相关推荐