When deserializing wallet extensions, lock order is now wallet and then extension.

This commit is contained in:
Jarl Fransson 2014-10-21 13:31:15 +02:00 committed by Andreas Schildbach
parent af20c37a8d
commit e3a13a6efa
2 changed files with 25 additions and 4 deletions

View File

@ -3972,6 +3972,26 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
}
}
/**
* Deserialize the wallet extension with the supplied data and add
* it to the wallet, unless there exists an extension with the
* same id.
*/
public void deserializeAndAddExtension(WalletExtension extension, byte[] data) throws Exception {
String id = checkNotNull(extension).getWalletExtensionID();
lock.lock();
try {
if (extensions.containsKey(id)) {
return;
} else {
extension.deserializeWalletExtension(this, data);
addExtension(extension);
}
} finally {
lock.unlock();
}
}
@Override
public synchronized void setTag(String tag, ByteString value) {
super.setTag(tag, value);

View File

@ -513,17 +513,18 @@ public class WalletProtobufSerializer {
} else {
log.info("Loading wallet extension {}", id);
try {
extension.deserializeWalletExtension(wallet, extProto.getData().toByteArray());
wallet.addOrGetExistingExtension(extension);
wallet.deserializeAndAddExtension(extension, extProto.getData().toByteArray());
} catch (Exception e) {
if (extProto.getMandatory() && requireMandatoryExtensions)
if (extProto.getMandatory() && requireMandatoryExtensions) {
log.error("Error whilst reading extension {}, failing to read wallet", id, e);
throw new UnreadableWalletException("Could not parse mandatory extension in wallet: " + id);
else
} else {
log.error("Error whilst reading extension {}, ignoring", id, e);
}
}
}
}
}
/**
* Returns the loaded protocol buffer from the given byte stream. You normally want