(kvIndex uint64, encodedBlob []byte, commit common.Hash, contractMeta [32]byte)
| 325 | } |
| 326 | |
| 327 | func (s *StorageManager) commitEncodedBlob(kvIndex uint64, encodedBlob []byte, commit common.Hash, contractMeta [32]byte) error { |
| 328 | // the commit is different with what we got from the contract, so should not commit |
| 329 | if err := CompareCommits(contractMeta[32-HashSizeInContract:32], commit.Bytes()); err != nil { |
| 330 | return err |
| 331 | } |
| 332 | |
| 333 | m, success, err := s.shardManager.TryReadMeta(kvIndex) |
| 334 | if !success || err != nil { |
| 335 | return errors.New("metadata read failed") |
| 336 | } |
| 337 | |
| 338 | contractKvIdx := new(big.Int).SetBytes(contractMeta[0:5]).Uint64() |
| 339 | if contractKvIdx != kvIndex { |
| 340 | return errors.New("kvIdx from contract and input is not matched") |
| 341 | } |
| 342 | |
| 343 | localMeta := common.Hash{} |
| 344 | copy(localMeta[:], m) |
| 345 | |
| 346 | // the local already have the data and we do not need to commit |
| 347 | // empty filled case: if both of the hash is 0, but local meta shows this encodedBlob hasn't been filled yet, we should also commit |
| 348 | if bytes.Equal(localMeta[0:HashSizeInContract], commit[0:HashSizeInContract]) && (localMeta[HashSizeInContract]&blobFillingMask) != 0 { |
| 349 | return nil |
| 350 | } |
| 351 | |
| 352 | c := PrepareCommit(commit) |
| 353 | |
| 354 | success, err = s.shardManager.TryWriteEncoded(kvIndex, encodedBlob, c) |
| 355 | if !success || err != nil { |
| 356 | return errors.New("encodedBlob write failed") |
| 357 | } |
| 358 | return nil |
| 359 | } |
| 360 | |
| 361 | func (s *StorageManager) syncCheck(kvIdx uint64) error { |
| 362 | meta, success, err := s.shardManager.TryReadMeta(kvIdx) |
no test coverage detected